Repository navigation
http2: allocate on every chunk send #16669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
http2: allocate on every chunk send
Previously, we were using a shared stack allocated buffer to hold the serialized outbound data but that runs into issues if the outgoing stream does not write or copy immediately. Instead, allocate a buffer each time. Slight additional overhead here, but necessary. Later on, once we've analyzed this more, we might be able to switch to a stack allocated ring or slab buffer but that's a bit more complicated than what we strictly need right now.
- Loading branch information
commit 125e1b5c0dd9891479c5c9e79823f4e43bf8bce5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -893,32 +893,33 @@ int Http2Session::DoWrite(WriteWrap* req_wrap, | |
| return 0; | ||
| } | ||
|
|
||
| void Http2Session::AllocateSend(uv_buf_t* buf) { | ||
| buf->base = stream_alloc(); | ||
| buf->len = kAllocBufferSize; | ||
| size_t Http2Session::AllocateSend(WriteWrap** req) { | ||
| HandleScope scope(env()->isolate()); | ||
| auto AfterWrite = [](WriteWrap* req, int status) { | ||
| req->Dispose(); | ||
| }; | ||
| Local<Object> obj = | ||
| env()->write_wrap_constructor_function() | ||
| ->NewInstance(env()->context()).ToLocalChecked(); | ||
| // Base the amount allocated on the remote peers max frame size | ||
| uint32_t size = | ||
| nghttp2_session_get_remote_settings( | ||
| session(), | ||
| NGHTTP2_SETTINGS_MAX_FRAME_SIZE); | ||
| *req = WriteWrap::New(env(), obj, this, AfterWrite, size); | ||
| return size; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather have this return the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that works also |
||
| } | ||
|
|
||
| void Http2Session::Send(uv_buf_t* buf, size_t length) { | ||
| void Http2Session::Send(WriteWrap* req, char* buf, size_t length) { | ||
| DEBUG_HTTP2("Http2Session: Attempting to send data\n"); | ||
| if (stream_ == nullptr || !stream_->IsAlive() || stream_->IsClosing()) { | ||
| return; | ||
| } | ||
| HandleScope scope(env()->isolate()); | ||
| auto AfterWrite = [](WriteWrap* req_wrap, int status) { | ||
| req_wrap->Dispose(); | ||
| }; | ||
| Local<Object> req_wrap_obj = | ||
| env()->write_wrap_constructor_function() | ||
| ->NewInstance(env()->context()).ToLocalChecked(); | ||
| WriteWrap* write_req = WriteWrap::New(env(), | ||
| req_wrap_obj, | ||
| this, | ||
| AfterWrite); | ||
|
|
||
| chunks_sent_since_last_write_++; | ||
| uv_buf_t actual = uv_buf_init(buf->base, length); | ||
| if (stream_->DoWrite(write_req, &actual, 1, nullptr)) { | ||
| write_req->Dispose(); | ||
| uv_buf_t actual = uv_buf_init(buf, length); | ||
| if (stream_->DoWrite(req, &actual, 1, nullptr)) { | ||
| req->Dispose(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it 4x smaller than previously (which was equivalent to default window size + frame headers). Is that ok?
It could also potentially be allocating more than it needs to if the current available window size isn't very big.
Even if that's all fine, I think it needs
+ 9(could define this elsewhere to be less magicky) because this doesn't account for the frame header.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the +9. Going to keep benchmarking for a good allocation size