Faster reading of request body and headers #362
Merged
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.
Based on this comment that I agree with from @Macarse #253 (review)
The request reading is very inefficient by reading 1 byte at a time. In theory the OS might be buffering much more data because it knows how inefficient that is, but we should still see significant speed improvements by reading large amounts of data at once. This is due to the large amount of buffer allocation thrash.
The new approach is to read up to 1KB of request data in one shot. Now, a response with 4,500 bytes would see 4x 1024B reads, and then a 404 byte read to finish up. Before this PR, it would be 4,500 individual reads.
I also changed the unit test mock Socket to use actual OS sockets. This way we can test the read read flows!