From 427c0bc7c3566b4db5287679704baf211f65a76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 2 Aug 2020 20:06:49 +0200 Subject: [PATCH] aquatic_http: add keep_alive setting (default true) This might be good for performance in the real world. It also enables fairer load test comparisons with opentracker, which in my understanding drops connections after sending responses. --- aquatic_http/src/lib/config.rs | 2 ++ aquatic_http/src/lib/network/mod.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/aquatic_http/src/lib/config.rs b/aquatic_http/src/lib/config.rs index a2e5504..f0057d6 100644 --- a/aquatic_http/src/lib/config.rs +++ b/aquatic_http/src/lib/config.rs @@ -55,6 +55,7 @@ pub struct NetworkConfig { pub ipv6_only: bool, #[serde(flatten)] pub tls: TlsConfig, + pub keep_alive: bool, pub poll_event_capacity: usize, pub poll_timeout_microseconds: u64, } @@ -128,6 +129,7 @@ impl Default for NetworkConfig { address: SocketAddr::from(([0, 0, 0, 0], 3000)), ipv6_only: false, tls: TlsConfig::default(), + keep_alive: true, poll_event_capacity: 4096, poll_timeout_microseconds: 10_000, } diff --git a/aquatic_http/src/lib/network/mod.rs b/aquatic_http/src/lib/network/mod.rs index 78c4a70..2dc17ad 100644 --- a/aquatic_http/src/lib/network/mod.rs +++ b/aquatic_http/src/lib/network/mod.rs @@ -115,6 +115,7 @@ pub fn run_poll_loop( if !(local_responses.is_empty() & (response_channel_receiver.is_empty())) { send_responses( + &config, &mut response_buffer, local_responses.drain(..), response_channel_receiver.try_iter(), @@ -304,6 +305,7 @@ pub fn handle_connection_read_event( /// Read responses from channel, send to peers pub fn send_responses( + config: &Config, buffer: &mut Cursor<&mut [u8]>, local_responses: Drain<(ConnectionMeta, Response)>, channel_responses: crossbeam_channel::TryIter<(ConnectionMeta, Response)>, @@ -327,7 +329,9 @@ pub fn send_responses( Ok(()) => { debug!("sent response"); - // established.shutdown(); + if !config.network.keep_alive { + connections.remove(&meta.poll_token); + } }, Err(err) if err.kind() == ErrorKind::WouldBlock => { debug!("send response: would block");