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.
This commit is contained in:
Joakim Frostegård 2020-08-02 20:06:49 +02:00
parent 8caae958fd
commit 427c0bc7c3
2 changed files with 7 additions and 1 deletions

View file

@ -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,
}

View file

@ -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");