-
Notifications
You must be signed in to change notification settings - Fork 581
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
Added ability to specify custom ArrayPool #1190
Conversation
projects/RabbitMQ.Client/client/impl/AsyncConsumerDispatcher.cs
Outdated
Show resolved
Hide resolved
projects/RabbitMQ.Client/client/impl/ConcurrentConsumerDispatcher.cs
Outdated
Show resolved
Hide resolved
@lukebakken , can we have this patch for 6.x ? For 7.x, it's better to use |
Whoops, wrong milestone. Fixed. I'm keeping an eye out for when this is ready to review. |
@sungam3r , should I add a new property to |
Yes, API approval tests work so. |
e4ffd50
to
7fe5acb
Compare
Review feedback Added MemoryPool property to approved API Prefer a ctor argument to specify your own ArrayPool<byte>
7fe5acb
to
f5bf954
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinging @bollhals @danielmarbach and @stebet to see if they have any input. This is a change that would go into version 6.3.0 only.
On vacation. Can only look next to week. Otherwise feel free to proceed |
See my comment in the issue, to which I didn't get an answer yet. => I don't see a real world use case where the selection of the memory pool helps solving an issue. So I wouldn't take this unless it is understood why and when. Just being able to switch the memory manager, doesn't solve anything on its own, as we're still copying the data to another buffer than the one you provide in the publish. |
For reference And I agree with the comment |
Thanks everyone for the feedback. I need to more carefully re-review the #1184 discussion. |
@bollhals , changing |
So your issue therefore is more about the arrays being retained too long inside the shared pool, right? |
@bollhals , not only this. There are few reasons causing OOM:
Custom |
@lukebakken , we are using ArrayPool<T>.Create factory method from .NET to achieve necessary performance optimizations (still not the best option, but acceptable). For now, we see no reason to provide custom implementation of the pool. However, in 7.x we would like to see |
Thanks for commenting. So for me this PR is acceptable if
|
Just as a comment, Json.net has a very similar extension point for the same reasons: http://james.newtonking.com/archive/2015/12/20/json-net-8-0-release-1-allocations-and-bug-fixes |
How common is the scenario with a lot of cores but little memory available to the runtime? |
k8s containers, for instance. We have 1 Gb limit per container. Due to LOH fragmentation, even 2 Gb can't help. |
@sakno OK but how many CPU resources do your pods have? We mostly see environments that are limited in every kind of resource, or those that have plenty of both CPU and memory. I'm |
@michaelklishin , CPU limit causes throttling on k8s for .NET application (for instance, dotnet/aspnetcore#29150) sometimes. So we use limits for RAM only. 8 cores are visible to the container. |
Fair enough. Then if it's worth the time investment and the default scenario is marginally affected, as @bollhals suggests, merging this would be a net positive for .NET on Kubernetes users :) |
Dear colleagues, have you faced any troubles with this pull-request? I am really waiting for the new library version with these changes. |
No, I just haven't had time to run any benchmarks to ensure these changes don't affect the normal case. |
Technically, access to the static field (ArrayPool.Shared) is replaced by instance field. From assembler point of view, both types of access are mov instruction. |
@sakno thanks! |
Proposed Changes
This change is aimed to fix inefficient memory pooling as described and discussed in #1184. It allows to specify custom
ArrayPool<byte>
throughConnectionFactory
instead ofArrayPool<byte>.Shared
.Types of Changes
What types of changes does your code introduce to this project?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creatingthe PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.
CONTRIBUTING.md
documentFurther Comments
Unfortunately, 6.x branch is based on .NET Standard 2.0. This target framework doesn't support
ReadAsync
/WriteAsync
stream overloads supportingReadOnlyMemory<byte>
type. Thus,MemoryPool<byte>
is not applicable here.