From a22b1e2e7e89f746aaeb46bcc188cbf5c048204f Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 29 Oct 2015 14:38:52 +0000 Subject: [PATCH] some tuning of buffer/write record sizes git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1711283 13f79535-47bb-0310-9956-ffa450edef68 --- modules/http2/h2_conn_io.c | 15 ++++++++++----- modules/http2/h2_session.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/http2/h2_conn_io.c b/modules/http2/h2_conn_io.c index 34b4c30bf8..6c194d9306 100644 --- a/modules/http2/h2_conn_io.c +++ b/modules/http2/h2_conn_io.c @@ -28,16 +28,21 @@ #include "h2_h2.h" #include "h2_util.h" -#define WRITE_BUFFER_SIZE (128*1024) +#define TLS_DATA_MAX (16*1024) + /* Calculated like this: assuming MTU 1500 bytes * 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) * - TLS overhead (60-100) * ~= 1300 bytes */ #define WRITE_SIZE_INITIAL 1300 -/* Calculated like this: max TLS record size - * 16*1024 - * - TLS overhead (60-100) */ -#define WRITE_SIZE_MAX (16*1024 - 100) +/* Calculated like this: max TLS record size 16*1024 + * - 40 (IP) - 20 (TCP) - 40 (TCP options) + * - TLS overhead (60-100) + * which seems to create less TCP packets overall + */ +#define WRITE_SIZE_MAX (TLS_DATA_MAX - 100) + +#define WRITE_BUFFER_SIZE (8*WRITE_SIZE_MAX) apr_status_t h2_conn_io_init(h2_conn_io *io, conn_rec *c) { diff --git a/modules/http2/h2_session.c b/modules/http2/h2_session.c index 0f317ffb3a..37cc6a52aa 100644 --- a/modules/http2/h2_session.c +++ b/modules/http2/h2_session.c @@ -594,6 +594,20 @@ static int on_send_data_cb(nghttp2_session *ngh2, return h2_session_status_from_apr_status(status); } +static ssize_t on_data_source_read_length_cb(nghttp2_session *session, + uint8_t frame_type, int32_t stream_id, + int32_t session_remote_window_size, + int32_t stream_remote_window_size, + uint32_t remote_max_frame_size, + void *user_data) +{ + /* DATA frames add 9 bytes header plus 1 byte for padlen and additional + * padlen bytes. Keep below TLS maximum record size. + * TODO: respect pad bytes when we have that feature. + */ + return (16*1024 - 10); +} + #define NGH2_SET_CALLBACK(callbacks, name, fn)\ nghttp2_session_callbacks_set_##name##_callback(callbacks, fn) @@ -618,6 +632,7 @@ static apr_status_t init_callbacks(conn_rec *c, nghttp2_session_callbacks **pcb) NGH2_SET_CALLBACK(*pcb, on_begin_headers, on_begin_headers_cb); NGH2_SET_CALLBACK(*pcb, on_header, on_header_cb); NGH2_SET_CALLBACK(*pcb, send_data, on_send_data_cb); + NGH2_SET_CALLBACK(*pcb, data_source_read_length, on_data_source_read_length_cb); return APR_SUCCESS; } -- 2.50.0