GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing github.com — AdaptiveByteBufAllocator: Make pooling of AdaptiveByteBuf magazine local by chrisvest · Pull Request #14414 · netty/netty Conversation
Member
Motivation: To reduce the usage of FastThreadLocal and make the AdaptiveByteBufAllocator also play nice with virtual threads we should just pool the AdapativeByteBuf instances in the Magazines itself. Modifications: Remove usage of Recycler for pooling AdaptiveByteBuf Use a bounded MPMC queue that is stored in the Magazine itself for pooling these instances Result: Fixes #14279
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
@normanmaurer I was investigating why there were test failures on #14332 and tried to recreate the PR from first principles. Regardless, I ended up with a very similar but slightly different implementation. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
imho this usage is really odd as if this methods returns non null its a ByteBuf which has a lifetime. I know that this would just be the same as into and so its fine to not release but this is more an implementation detail and very confusing and fragile.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Like stated below I think this method implementation is fragile and confusing. Depending on if buf is null or not we might need to release the returned AdaptiveByteBuf. This makes lifecycle management error-prone. Let's rework this somehow
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking a lot about the need to signal failure and the need to return a buffer, and the conflict between those two will always produce complicated code. So instead I'll try to side-step the problem by pushing the fallback paths down, and make this method infallible.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm all in to have this - it trades the virtue of simplicity with some cost in the optimized common path i.e.
Another option could be to have a Recycler impl which has the same tunable we're used to AND using a pluggable concept of ownership. I'm preparing a small PoC to show what I mean |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@normanmaurer Take a look. The allocate method does the fallback allocation now, instead of communicating potential allocation failure. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 any other comments or can we merge this one ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yep this morning I can share my proposal, yesterday I have been sidetracked the whole day : 🙏 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 ok just so I am sure I understood correctly... we should hold back until you shared your proposal, correct ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yess please 🥺 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
if this is happening why holding the lock there's no need the q to be mpmc
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
if this is happening why holding the lock there's no need the q to be mpmc
This @chrisvest ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but I want to have a full CI run backing up any move away from MPMC.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here in the thread-local case, we'll go to the Magazine.EVENT_LOOP_LOCAL_BUFFER_POOL, which uses MPSC under the hood.
When magazines are sharable, they may be used as fallbacks, which do not involve locking the magazine.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@normanmaurer @chrisvest it -> https://github.com/franz1981/netty/tree/4.1-mag-local-pool I'm not fixing the comment at #14414 (comment) or the ones from Norman, but proposing a different fast(er)-path for event loop confined magazines (as usual :P ) The branch I've sent got a sole concern, perf wise:
An "easy" solution to this would be to have
wdyt? I can add an additional commit to fix this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 The two approaches sound equivalent in terms of code style, so we could just let the benchmarks decide. So how about we look at that in a follow-up? I know it can take lot of time to tweak benchmarks back and forth. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Right now I suggest already to bring the fast thread local solution in too - which uses array deq for the fastest path - which is very difficult to beat, unless there is something very wrong in fast thread local or elsewhere (the handle availability). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2baa8c2 to
c5a0cc6
Compare
|
@chrisvest I've sent by accident my changes into your branch - now I've forcibly pushed your original commits removing mine :"( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Motivation: To reduce the usage of FastThreadLocal and make the AdaptiveByteBufAllocator also play nice with virtual threads we should just pool the AdapativeByteBuf instances in the Magazines itself. Modifications: Remove usage of Recycler for pooling AdaptiveByteBuf Use a bounded MPMC queue that is stored in the Magazine itself for pooling these instances Result: Fixes netty#14279
c5a0cc6 to
b2bbd8d
Compare
…cal #14414 Motivation: To reduce the usage of FastThreadLocal and make the AdaptiveByteBufAllocator also play nice with virtual threads we should just pool the AdapativeByteBuf instances in the Magazines itself. Modifications: Remove usage of Recycler for pooling AdaptiveByteBuf Use a bounded MPMC queue that is stored in the Magazine itself for pooling these instances Result: Fixes #14279
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Don't use Netty recyclers for the adaptive ByteBuf pool, but leverage magazine-local ones
There was an error while loading. Please reload this page.