Skip to content

Commit

Permalink
fix: throughput accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc committed Jan 10, 2024
1 parent d7d94fb commit c05539d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ tokio = "1"
tokio-util = "0.7"
tokio_chacha20 = { git = "https://github.com/Banyc/tokio_chacha20.git", rev = "40d2030f0ab6e7e32031e61618717d25f25e5509" }
tokio_kcp = "0.9"
tokio_throughput = { git = "https://github.com/Banyc/tokio_throughput.git", rev = "e45535cfce6aa87d903ef5665c6f3d3b25a9d1ab" }
tokio_throughput = { git = "https://github.com/Banyc/tokio_throughput.git", rev = "80cbf0572623762665caff07781cee3e0d97cfc7" }
tracing = "0.1"
tracing-subscriber = "0.3"
10 changes: 4 additions & 6 deletions common/src/stream/io_copy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
use async_speed_limit::Limiter;
use metrics::{counter, gauge};
use scopeguard::defer;
use strict_num::NormalizedF64;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_throughput::{ReadGauge, WriteGauge};
use tracing::info;
Expand All @@ -22,7 +21,6 @@ use super::{
pub mod tokio_io;

pub const DEAD_SESSION_RETENTION_DURATION: Duration = Duration::from_secs(5);
const ALPHA: f64 = 0.1;

pub struct CopyBidirectional<DS, US, ST> {
pub downstream: DS,
Expand All @@ -48,8 +46,8 @@ where
log_prefix: &str,
) -> (StreamMetrics<ST>, Result<(), tokio_io::CopyBiErrorKind>) {
let session = session_table.map(|s| {
let (up_handle, up) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (dn_handle, dn) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (up_handle, up) = tokio_throughput::gauge();
let (dn_handle, dn) = tokio_throughput::gauge();
let r = ReadGauge(up);
let w = WriteGauge(dn);

Expand Down Expand Up @@ -85,8 +83,8 @@ where
Result<(), tokio_io::CopyBiErrorKind>,
) {
let session = session_table.map(|s| {
let (up_handle, up) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (dn_handle, dn) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (up_handle, up) = tokio_throughput::gauge();
let (dn_handle, dn) = tokio_throughput::gauge();
let r = ReadGauge(up);
let w = WriteGauge(dn);

Expand Down
10 changes: 4 additions & 6 deletions common/src/udp/io_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
use async_speed_limit::Limiter;
use metrics::{counter, gauge};
use scopeguard::defer;
use strict_num::NormalizedF64;
use thiserror::Error;
use tokio::{net::UdpSocket, sync::mpsc};
use tokio_throughput::{ReadGauge, WriteGauge};
Expand All @@ -26,7 +25,6 @@ use super::{
};

const DEAD_SESSION_RETENTION_DURATION: Duration = Duration::from_secs(5);
const ALPHA: f64 = 0.1;

pub trait UdpRecv {
fn trait_recv(
Expand Down Expand Up @@ -73,8 +71,8 @@ where
log_prefix: &str,
) -> Result<FlowMetrics, CopyBiError> {
let session = session_table.as_ref().map(|s| {
let (up_handle, up) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (dn_handle, dn) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (up_handle, up) = tokio_throughput::gauge();
let (dn_handle, dn) = tokio_throughput::gauge();
let r = ReadGauge(up);
let w = WriteGauge(dn);

Expand Down Expand Up @@ -103,8 +101,8 @@ where
log_prefix: &str,
) -> Result<FlowMetrics, CopyBiError> {
let session = session_table.as_ref().map(|s| {
let (up_handle, up) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (dn_handle, dn) = tokio_throughput::gauge(NormalizedF64::new(ALPHA).unwrap());
let (up_handle, up) = tokio_throughput::gauge();
let (dn_handle, dn) = tokio_throughput::gauge();
let r = ReadGauge(up);
let w = WriteGauge(dn);

Expand Down

0 comments on commit c05539d

Please sign in to comment.