feat(http2): add http2_max_send_buf_size option to client and server

This value is like a high-water mark. It applies per stream. Once a
stream has buffered that amount of bytes to send, it won't poll more
data from the `HttpBody` until the stream has been able to flush under
it.
This commit is contained in:
Sean McArthur
2021-12-08 15:03:00 -08:00
parent 84b78b6c87
commit bff977b73c
7 changed files with 68 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ use crate::{Body, Response};
const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb
#[derive(Clone, Debug)]
pub(crate) struct Config {
@@ -45,6 +46,7 @@ pub(crate) struct Config {
pub(crate) keep_alive_interval: Option<Duration>,
#[cfg(feature = "runtime")]
pub(crate) keep_alive_timeout: Duration,
pub(crate) max_send_buffer_size: usize,
}
impl Default for Config {
@@ -59,6 +61,7 @@ impl Default for Config {
keep_alive_interval: None,
#[cfg(feature = "runtime")]
keep_alive_timeout: Duration::from_secs(20),
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
}
}
}
@@ -109,7 +112,8 @@ where
builder
.initial_window_size(config.initial_stream_window_size)
.initial_connection_window_size(config.initial_conn_window_size)
.max_frame_size(config.max_frame_size);
.max_frame_size(config.max_frame_size)
.max_send_buffer_size(config.max_send_buffer_size);
if let Some(max) = config.max_concurrent_streams {
builder.max_concurrent_streams(max);
}