Limit the number of concurrent streams per client

This commit is contained in:
Frank Denis 2021-02-15 23:35:05 +01:00
parent a2f342379e
commit b4d4eaae50
5 changed files with 14 additions and 0 deletions

View file

@ -14,6 +14,7 @@ pub fn parse_opts(globals: &mut Globals) {
let max_clients = MAX_CLIENTS.to_string(); let max_clients = MAX_CLIENTS.to_string();
let timeout_sec = TIMEOUT_SEC.to_string(); let timeout_sec = TIMEOUT_SEC.to_string();
let max_concurrent_streams = MAX_CONCURRENT_STREAMS.to_string();
let min_ttl = MIN_TTL.to_string(); let min_ttl = MIN_TTL.to_string();
let max_ttl = MAX_TTL.to_string(); let max_ttl = MAX_TTL.to_string();
let err_ttl = ERR_TTL.to_string(); let err_ttl = ERR_TTL.to_string();
@ -62,6 +63,14 @@ pub fn parse_opts(globals: &mut Globals) {
.default_value(&max_clients) .default_value(&max_clients)
.help("Maximum number of simultaneous clients"), .help("Maximum number of simultaneous clients"),
) )
.arg(
Arg::with_name("max_concurrent")
.short("C")
.long("max-concurrent")
.takes_value(true)
.default_value(&max_concurrent_streams)
.help("Maximum number of concurrent requests per client"),
)
.arg( .arg(
Arg::with_name("timeout") Arg::with_name("timeout")
.short("t") .short("t")
@ -152,6 +161,7 @@ pub fn parse_opts(globals: &mut Globals) {
} }
globals.max_clients = matches.value_of("max_clients").unwrap().parse().unwrap(); globals.max_clients = matches.value_of("max_clients").unwrap().parse().unwrap();
globals.timeout = Duration::from_secs(matches.value_of("timeout").unwrap().parse().unwrap()); globals.timeout = Duration::from_secs(matches.value_of("timeout").unwrap().parse().unwrap());
globals.max_concurrent_streams = matches.value_of("max_concurrent").unwrap().parse().unwrap();
globals.min_ttl = matches.value_of("min_ttl").unwrap().parse().unwrap(); globals.min_ttl = matches.value_of("min_ttl").unwrap().parse().unwrap();
globals.max_ttl = matches.value_of("max_ttl").unwrap().parse().unwrap(); globals.max_ttl = matches.value_of("max_ttl").unwrap().parse().unwrap();
globals.err_ttl = matches.value_of("err_ttl").unwrap().parse().unwrap(); globals.err_ttl = matches.value_of("err_ttl").unwrap().parse().unwrap();

View file

@ -1,5 +1,6 @@
pub const LISTEN_ADDRESS: &str = "127.0.0.1:3000"; pub const LISTEN_ADDRESS: &str = "127.0.0.1:3000";
pub const MAX_CLIENTS: usize = 512; pub const MAX_CLIENTS: usize = 512;
pub const MAX_CONCURRENT_STREAMS: u32 = 16;
pub const PATH: &str = "/dns-query"; pub const PATH: &str = "/dns-query";
pub const SERVER_ADDRESS: &str = "9.9.9.9:53"; pub const SERVER_ADDRESS: &str = "9.9.9.9:53";
pub const TIMEOUT_SEC: u64 = 10; pub const TIMEOUT_SEC: u64 = 10;

View file

@ -22,6 +22,7 @@ pub struct Globals {
pub max_clients: usize, pub max_clients: usize,
pub timeout: Duration, pub timeout: Duration,
pub clients_count: ClientsCount, pub clients_count: ClientsCount,
pub max_concurrent_streams: u32,
pub min_ttl: u32, pub min_ttl: u32,
pub max_ttl: u32, pub max_ttl: u32,
pub err_ttl: u32, pub err_ttl: u32,

View file

@ -287,6 +287,7 @@ impl DoH {
let mut server = Http::new(); let mut server = Http::new();
server.http1_keep_alive(self.globals.keepalive); server.http1_keep_alive(self.globals.keepalive);
server.http2_max_concurrent_streams(self.globals.max_concurrent_streams);
server.pipeline_flush(true); server.pipeline_flush(true);
let executor = LocalExecutor::new(self.globals.runtime_handle.clone()); let executor = LocalExecutor::new(self.globals.runtime_handle.clone());
let server = server.with_executor(executor); let server = server.with_executor(executor);

View file

@ -36,6 +36,7 @@ fn main() {
max_clients: MAX_CLIENTS, max_clients: MAX_CLIENTS,
timeout: Duration::from_secs(TIMEOUT_SEC), timeout: Duration::from_secs(TIMEOUT_SEC),
clients_count: Default::default(), clients_count: Default::default(),
max_concurrent_streams: MAX_CONCURRENT_STREAMS,
min_ttl: MIN_TTL, min_ttl: MIN_TTL,
max_ttl: MAX_TTL, max_ttl: MAX_TTL,
err_ttl: ERR_TTL, err_ttl: ERR_TTL,