Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

RequestBody draining still allocates per-request buffers #334

Closed
rynowak opened this issue Nov 6, 2015 · 10 comments
Closed

RequestBody draining still allocates per-request buffers #334

rynowak opened this issue Nov 6, 2015 · 10 comments
Assignees
Milestone

Comments

@rynowak
Copy link
Member

rynowak commented Nov 6, 2015

This change: 4bba074

Fixed a serious allocation issue, but also added a 4kb buffer to each frame, which is more per-request allocation. Simply just making this static as well may not do what we want, as this might lead to a lot of contention for this cache line.

I think we need to revisit the original proposal which was to implement CopyToStreamAsync in a smarter way.

Allocation data for 3000 requests:
image

In my sample app, this is responsible for 12/82mb allocated

@rynowak
Copy link
Member Author

rynowak commented Nov 6, 2015

/cc @halter73 @benaadams

@benaadams
Copy link
Contributor

This is only on fresh connections, not keep alive already open connections?

Might be worth pooling it; since its just a reusable sink.

benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 6, 2015
@benaadams
Copy link
Contributor

Raised PR #335 "Use pooled array"

benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 6, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 6, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 6, 2015
@halter73
Copy link
Member

halter73 commented Nov 6, 2015

I guess I didn't look at the PR that added _nullBuffer closely enough. I thought _nullBuffer was static. Is there any reason it can't be? I think that would even be more efficient.

@rynowak
Copy link
Member Author

rynowak commented Nov 6, 2015

All of these solutions involve copy bytes from one location to another in memory. Wouldn't it be better to override CopyToAsync and special case Stream.Null?

@halter73
Copy link
Member

halter73 commented Nov 7, 2015

@rynowak That's definitely an option. We were considering a change to make CopyToAsync bufferless in all cases, but that seemed to be a little too complex for a last minute rc1 fix.

It might make more sense just to add a new method to FrameRequestStream that efficiently consumes the rest of the request rather than overriding CopyToAsync and checking if the argument is Stream.Null only to do the same thing.

@rynowak
Copy link
Member Author

rynowak commented Nov 7, 2015

⬆️ either of those would work.

@benaadams
Copy link
Contributor

I thought _nullBuffer was static. Is there any reason it can't be? I think that would even be more efficient.

Because you'll have multiple threads writing to it on different cores and cause cpu cache thrashing.

@benaadams
Copy link
Contributor

add a new method to FrameRequestStream that efficiently consumes the rest of the request

👍

Could even just call it directly in Frame; it constructs FrameRequestStream as a strong type in the same function

@benaadams
Copy link
Contributor

Something that fasts forwards to the end rather than doing the copy to a buffer would be better; as should be less work? (Less work for CPU rather than; for dev)

benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 8, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 9, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 9, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 10, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 10, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 11, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 11, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 13, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 13, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Nov 14, 2015
@davidfowl davidfowl added this to the 1.0.0-rc2 milestone Nov 16, 2015
@davidfowl davidfowl self-assigned this Nov 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants