-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add PipeOptions setting for retaining Memory after the PipeReader consumes it #26723
Comments
Here's the logic that handles this today: |
I would prefer this to be "leave N bytes worth of free segments in the pipe" option. |
No matter what the Now if If Kestrel were to ever use this feature, we'd probably need some time of timeout to eventually returning blocks after the Pipe is idle for long enough. |
Right, I originally had a bool but then I was thinking this should be more general and just let you describe how much memory you were willing to keep around.
Agreed. We could look into this as a general feature. The thing I think we need to have a way to solve today though is the inefficiency around renting and returning buffers that are fully consumed. There are some scenarios where the PipeReader's buffers are always fully consumed (like when writing to another sink) and those suffer the problem where the memory potentially gets returned if the reader is catching up with the writer. For e.g. small writes for example could cause the constant rent/return more often than it needs to.
Maybe, maybe we'd need to expose an explicit call to dump the consumed memory and a way to determine how much memory was consumed but not in use. This makes things a bit more complicated but gives the pipe creator more control... The first thing to do here is to get some benchmarks for scenarios we think might be faster (like writing output) and see if this moves the needle. |
We like this, but will leave it to a future milestone. |
Prototype (https://github.com/dotnet/corefx/compare/davidfowl/pool-harder) of basically never returning the rented memory and instead reusing them from the BufferSegment in the pipe. |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
Today, the
Pipe
implementation returns buffers to the underlying buffer pool as soon as the buffer is fully consumed by thePipeReader
. This is great for lowering memory usage but it causes more memory to be returned to the pool even if we haven't exhausted the current memory segment (the tail of the linked list).We should have an option to avoid this behavior so that the segment sticks around longer. This'll increases the idle memory usage but can be more efficient for scenarios where you are receiving continuous data or are willing to use more memory to reduce the amount of calls to Rent/Return on the underlying
MemoryPool<byte>
.The setting would default to 0 meaning that we don't allow any idle memory to sit around (this matches today's behavior). This could be set to anything between the Pipe's minimumSegmentSize setting and
MemoryPool<byte>.MaxBufferSize
.cc @pakrym @halter73 @mgravell
The text was updated successfully, but these errors were encountered: