Closed beckend closed 2 years ago
I'm not sure what "commenting out the for loop to send makes it go in snail speed" means, but I see you're calling std::thread::sleep
in async code. Do not do that; it will block the thread and prevent other work from being done. See https://ryhl.io/blog/async-what-is-blocking/.
Ok, thanks
I am trying to send continuous data, emulating in the future video and audio data. However it seems like spawn sending is superslow, commenting out the for loop to send makes it go in snail speed. The issues are much less when finishing the stream but the point is not to finish it.
The code can be found at: https://github.com/beckend/quinn-performance
main.rs
```rust mod common; use anyhow::{anyhow, Result}; use bytes::Bytes; use common::{make_client_endpoint, make_server_endpoint}; use futures_util::stream::StreamExt; use quinn::{Connection, Endpoint}; use std::{net::SocketAddr, thread, time::Duration}; #[tokio::main] async fn main() -> Result<()> { let addr1: SocketAddr = "127.0.0.1:5000".parse()?; let server1_cert = get_server(addr1)?; let client = make_client_endpoint("127.0.0.1:0".parse().unwrap(), &[&server1_cert]).unwrap(); let connection = get_client(&client, addr1).await?; let connection_c = std::sync::Arc::new(connection.clone()); tokio::spawn(async move { // for _ in 0..4 { // let connection_c = connection_c.clone(); // run_client_task(connection_c).await.unwrap(); // println!("done"); // } let connection_c = connection_c.clone(); run_client_task(connection_c).await.unwrap(); println!("done"); }) .await?; client.wait_idle().await; client.close(0u32.into(), b"done"); connection.close(0u32.into(), b"done"); println!("all done"); Ok(()) } fn get_server(addr: SocketAddr) -> Result