Skip to content

Commit

Permalink
http2: adjust stream buffer size
Browse files Browse the repository at this point in the history
Adjust stream buffer size to allow full 4 default-sized frames
including their frame headers to allow more efficient sending
of data to the socket.

PR-URL: #16445
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
apapirovski authored and gibfahn committed Oct 31, 2017
1 parent ea32d0e commit 24fd8ff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ int Http2Session::DoWrite(WriteWrap* req_wrap,
return 0;
}

void Http2Session::AllocateSend(size_t recommended, uv_buf_t* buf) {
void Http2Session::AllocateSend(uv_buf_t* buf) {
buf->base = stream_alloc();
buf->len = kAllocBufferSize;
}
Expand Down
5 changes: 3 additions & 2 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ class Http2Options {
padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
};

static const size_t kAllocBufferSize = 64 * 1024;
// This allows for 4 default-sized frames with their frame headers
static const size_t kAllocBufferSize = 4 * (16384 + 9);

typedef uint32_t(*get_setting)(nghttp2_session* session,
nghttp2_settings_id id);
Expand Down Expand Up @@ -414,7 +415,7 @@ class Http2Session : public AsyncWrap,
void OnFrameError(int32_t id, uint8_t type, int error_code) override;
void OnTrailers(Nghttp2Stream* stream,
const SubmitTrailers& submit_trailers) override;
void AllocateSend(size_t recommended, uv_buf_t* buf) override;
void AllocateSend(uv_buf_t* buf) override;

int DoWrite(WriteWrap* w, uv_buf_t* bufs, size_t count,
uv_stream_t* send_handle) override;
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2_core-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ inline void Nghttp2Session::SendPendingData() {
return;

uv_buf_t dest;
AllocateSend(SEND_BUFFER_RECOMMENDED_SIZE, &dest);
AllocateSend(&dest);
size_t destLength = 0; // amount of data stored in dest
size_t destRemaining = dest.len; // amount space remaining in dest
size_t destOffset = 0; // current write offset of dest
Expand Down
3 changes: 1 addition & 2 deletions src/node_http2_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Nghttp2Stream;
struct nghttp2_stream_write_t;

#define MAX_BUFFER_COUNT 16
#define SEND_BUFFER_RECOMMENDED_SIZE 4096

enum nghttp2_session_type {
NGHTTP2_SESSION_SERVER,
Expand Down Expand Up @@ -178,7 +177,7 @@ class Nghttp2Session {
virtual ssize_t GetPadding(size_t frameLength,
size_t maxFrameLength) { return 0; }
virtual void OnFreeSession() {}
virtual void AllocateSend(size_t suggested_size, uv_buf_t* buf) = 0;
virtual void AllocateSend(uv_buf_t* buf) = 0;

virtual bool HasGetPaddingCallback() { return false; }

Expand Down

0 comments on commit 24fd8ff

Please sign in to comment.