-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
http: implement slab allocation for HTTP header parsing #61375
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
Open
mertcanaltin
wants to merge
7
commits into
nodejs:main
Choose a base branch
from
mertcanaltin:mert/http-parser-slab-allocation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−49
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20bde47
http: implement slab allocation for HTTP header parsing
mertcanaltin 9115556
lint
mertcanaltin 5def150
benchmark: add fragmented HTTP header parsing benchmark
mertcanaltin 56393d3
implement shared slab allocation
mertcanaltin 266bfdb
rename Allocate call
mertcanaltin b9090c9
optimize StringPtrAllocator memory management
mertcanaltin 3d643fe
refactor StringPtr and Parser to use allocator parameter in Save and …
mertcanaltin 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
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| len: [8, 16], | ||
| frags: [2, 4, 8], | ||
| n: [1e5], | ||
| }, { | ||
| flags: ['--expose-internals', '--no-warnings'], | ||
| }); | ||
|
|
||
| function main({ len, frags, n }) { | ||
| const { HTTPParser } = common.binding('http_parser'); | ||
| const REQUEST = HTTPParser.REQUEST; | ||
| const kOnHeaders = HTTPParser.kOnHeaders | 0; | ||
| const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; | ||
| const kOnBody = HTTPParser.kOnBody | 0; | ||
| const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; | ||
|
|
||
| function processHeaderFragmented(fragments, n) { | ||
| const parser = newParser(REQUEST); | ||
|
|
||
| bench.start(); | ||
| for (let i = 0; i < n; i++) { | ||
| // Send header in fragments | ||
| for (const frag of fragments) { | ||
| parser.execute(frag, 0, frag.length); | ||
| } | ||
| parser.initialize(REQUEST, {}); | ||
| } | ||
| bench.end(n); | ||
| } | ||
|
|
||
| function newParser(type) { | ||
| const parser = new HTTPParser(); | ||
| parser.initialize(type, {}); | ||
|
|
||
| parser.headers = []; | ||
|
|
||
| parser[kOnHeaders] = function() { }; | ||
| parser[kOnHeadersComplete] = function() { }; | ||
| parser[kOnBody] = function() { }; | ||
| parser[kOnMessageComplete] = function() { }; | ||
|
|
||
| return parser; | ||
| } | ||
|
|
||
| // Build the header | ||
| let header = `GET /hello HTTP/1.1\r\nContent-Type: text/plain\r\n`; | ||
|
|
||
| for (let i = 0; i < len; i++) { | ||
| header += `X-Filler${i}: ${Math.random().toString(36).substring(2)}\r\n`; | ||
| } | ||
| header += '\r\n'; | ||
|
|
||
| // Split header into fragments | ||
| const headerBuf = Buffer.from(header); | ||
| const fragSize = Math.ceil(headerBuf.length / frags); | ||
| const fragments = []; | ||
|
|
||
| for (let i = 0; i < headerBuf.length; i += fragSize) { | ||
| fragments.push(headerBuf.slice(i, Math.min(i + fragSize, headerBuf.length))); | ||
| } | ||
|
|
||
| processHeaderFragmented(fragments, n); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.