Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

fix unnecessary body copying #346

Merged
merged 2 commits into from
Mar 14, 2019
Merged

fix unnecessary body copying #346

merged 2 commits into from
Mar 14, 2019

Conversation

tanner0101
Copy link
Member

@tanner0101 tanner0101 commented Mar 14, 2019

This PR fixes an issue that causes HTTP request body byte buffer to reallocate unnecessarily. During large file uploads, this issue quickly consumes the CPU.

Screen Shot 2019-03-13 at 9 23 33 PM

The reason for the copy is that HTTPServerState continues to hold a reference to the HTTP request ByteBuffer when the new chunk is written. Since the buffer is not uniquely referenced, the write triggers a copy.

To fix this, the request body buffer is moved outside of the state enum to a member var. This ensures the ByteBuffer is uniquely referenced during body collection.

@tanner0101 tanner0101 added the bug Something isn't working label Mar 14, 2019
@tanner0101 tanner0101 merged commit 24282b0 into 3 Mar 14, 2019
@penny-coin
Copy link

Hey @tanner0101, you just merged a pull request, have a coin!

You now have 1136 coins.

@tanner0101 tanner0101 deleted the fix-body-copying branch March 14, 2019 01:51
@calebkleveter
Copy link
Member

Is it possible to write a test case to make sure this doesn't happen again? Maybe just a performance test would do.

@tanner0101
Copy link
Member Author

@calebkleveter yeah I think a performance test for a large file upload would do the trick. I'll open an issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants