Skip to content

Commit fd88278

Browse files
authored
updating the time keeping in data_channel_flow_control that reports the actual throughput of the last loop. (#659)
1 parent 6cdafce commit fd88278

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/examples/data-channels-flow-control/data-channels-flow-control.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,28 @@ async fn create_responder() -> anyhow::Result<RTCPeerConnection> {
117117
Box::pin(async {
118118
// This callback shouldn't be blocked for a long time, so we spawn our handler
119119
tokio::spawn(async move {
120-
let start = SystemTime::now();
120+
let mut start = SystemTime::now();
121+
let mut last_total_bytes_received: usize = 0;
121122

122123
tokio::time::sleep(Duration::from_secs(1)).await;
123124
println!();
124125

125126
loop {
126127
let total_bytes_received =
127128
shared_total_bytes_received.load(Ordering::Relaxed);
129+
let epoch_bytes_received =
130+
total_bytes_received - last_total_bytes_received;
131+
last_total_bytes_received = total_bytes_received;
128132

129133
let elapsed = SystemTime::now().duration_since(start);
130134
let bps =
131-
(total_bytes_received * 8) as f64 / elapsed.unwrap().as_secs_f64();
135+
(epoch_bytes_received * 8) as f64 / elapsed.unwrap().as_secs_f64();
132136

133137
println!(
134138
"Throughput is about {:.03} Mbps",
135139
bps / (1024 * 1024) as f64
136140
);
141+
start = SystemTime::now();
137142
tokio::time::sleep(Duration::from_secs(1)).await;
138143
}
139144
});

0 commit comments

Comments
 (0)