GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Specialize Adaptive's allocator Recycler based on magazine's owner by franz1981 · Pull Request #14421 · netty/netty

Conversation

@franz1981

@franz1981 franz1981 commented Oct 28, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Motivation:
EventLoop local magazines are treated the same as shared ones

Modifications:
Use existing Recycler(s) on un-shared magazines to save expensive atomic operations while reusing adaptive buffers

Result:
Further improve #14279 for the common path i.e. event loops

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@franz1981
franz1981 requested a review from normanmaurer October 28, 2024 13:02
@franz1981

franz1981 commented Oct 28, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@normanmaurer this is on top of #14414 just to ease reviewing it

The actual changes are the ones at 2baa8c208a291723ae6fe186cbe4b924518c2acb

And are not definitive enough because of #14414 (comment)

TLDR we have a potentially megamorphic call on the Handle at AdpativeByteBuf::deallocate: I would like to improve such too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 requested a review from chrisvest October 28, 2024 16:22
@franz1981

franz1981 commented Oct 30, 2024

Copy link
Copy Markdown
Contributor Author

@normanmaurer @chrisvest I've gotten rid of the megamorphic call mentioned at #14421 (comment) by adding 2c3b15c50daed0f4b6a93a34568e2e9f6c304520

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chrisvest
chrisvest approved these changes Nov 6, 2024
View reviewed changes
@chrisvest

chrisvest commented Nov 6, 2024

Copy link
Copy Markdown
Member

I tried running benchmarks with this, but I'm not seeing much improvement. I used 10 forks in these runs:

#14414:

Benchmark                                             (size)   Mode  Cnt         Score        Error  Units
ByteBufAllocatorBenchmark.adaptiveDirectAllocAndFree   00256  thrpt  100  18495157.592 ± 253756.522  ops/s
ByteBufAllocatorBenchmark.adaptiveHeapAllocAndFree     00256  thrpt  100  20277970.413 ± 428136.189  ops/s

Benchmark                                                    (size)   Mode  Cnt         Score         Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt  100  79617949.492 ± 6718078.227  ops/s

#14421:

Benchmark                                             (size)   Mode  Cnt         Score         Error  Units
ByteBufAllocatorBenchmark.adaptiveDirectAllocAndFree   00256  thrpt  100  16641428.737 ± 1887660.133  ops/s
ByteBufAllocatorBenchmark.adaptiveHeapAllocAndFree     00256  thrpt  100  20258834.173 ±  112095.227  ops/s

Benchmark                                                    (size)   Mode  Cnt         Score         Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt  100  79411577.078 ± 9787056.407  ops/s
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Nov 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Are u using an apple processor?
They way apple handle uncontended atomic is slightly different from x86 (Intel/AMD specifically); I will re run (with profiling) the same benchmark, in case.
The other reason is that maybe "something" (perf will tell me) in fast thread local doesn't make it as good as we hope for this use case OR the benchmark is not stressing what we believe it stress (this one seems the more likely to me)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

As expected by my own comment at

OR the benchmark is not stressing what we believe it stress (this one seems the more likely to me)

running the ByteBufAllocatorConcurrentBenchmar benchmark on this branch shows that something is off:

image

which means that despite the jmh executor should be an event loop, the magazine used is NOT event loop local.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Nov 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

And it seems @chrisvest that you need to set

and the actual behaviour reflect how good this optimization is

image

As you can see the number of atomic ops are much reduced and numbers have changed accordly

This PR without -Dio.netty.allocator.useCachedMagazinesForNonEventLoopThreads=true

Benchmark                                                    (size)   Mode  Cnt        Score        Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt   20  8959741.229 ± 149752.335  ops/s

Now, adding the proper configuration i.e. -Dio.netty.allocator.useCachedMagazinesForNonEventLoopThreads=true
in order to make the custom harness executor to be considered OK by the adaptive allocator despite not been an event loop.

This PR:

Benchmark                                                    (size)   Mode  Cnt         Score        Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt   20  13629020.463 ± 801453.039  ops/s

Before this PR:

Benchmark                                                    (size)   Mode  Cnt         Score        Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt   20  11208779.418 ± 210872.723  ops/s

There's some improvement (as expected) - but I still see too many compareAndSet in the profiling data shown in this comment; investigating.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

As per

There's some improvement (as expected) - but I still see too many compareAndSet in the profiling data shown in this comment; investigating.

I was wrong: it seems that we have 2 compareAndSet (which are too much IMO) - one for Chunk::release and one (which "shield" it) on the adaptive ByteBuf itself (on release) :"(
I would like to have just one and this will further "fly"

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer approved these changes Nov 7, 2024
View reviewed changes
@normanmaurer

normanmaurer commented Nov 7, 2024

Copy link
Copy Markdown
Member

Should we merge #14414 first and just rebase this one as a "follow up" ?

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented Nov 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

sure things, I would wait @chrisvest feedbacks after adding that option I suggested; x86 is not the only arch we would like to make happy I think 🤔

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Nov 7, 2024

Copy link
Copy Markdown
Member

Are u using an apple processor?

Yes.

I reran the benchmark with the option, and see some improvements as well:

#14414
Benchmark                                                    (size)   Mode  Cnt         Score         Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt  100  83700665.953 ± 9595346.585  ops/s

#14421
Benchmark                                                    (size)   Mode  Cnt         Score          Error  Units
ByteBufAllocatorConcurrentBenchmark.allocateReleaseAdaptive   00256  thrpt  100  95217417.876 ± 12041757.914  ops/s

We need to look into why the JMH executor setting isn't having the effect we expect.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Nov 7, 2024

Copy link
Copy Markdown
Member

Should we merge #14414 first and just rebase this one as a "follow up" ?

That's what I originally suggested. No harm in iterating on things over multiple PRs as long as they individually don't break things.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Nov 7, 2024

Copy link
Copy Markdown
Member

Please do @chrisvest

chrisvest reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.1-mag-local-pool branch 3 times, most recently from dbc9e75 to b711ad0 Compare November 8, 2024 08:07
@franz1981
franz1981 marked this pull request as ready for review November 8, 2024 08:08
@franz1981
franz1981 force-pushed the 4.1-mag-local-pool branch from b711ad0 to 3e45566 Compare November 8, 2024 08:13
@normanmaurer normanmaurer added this to the 4.1.115.Final milestone Nov 8, 2024
normanmaurer
normanmaurer approved these changes Nov 8, 2024
View reviewed changes

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
chrisvest
chrisvest approved these changes Nov 8, 2024
View reviewed changes
@normanmaurer

normanmaurer commented Nov 9, 2024

Copy link
Copy Markdown
Member

@franz1981 feel free to pull in

franz1981 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
Specialize Adaptive's allocator Recycler based on magazine's owner
35b1980
Motivation:
EventLoop local magazines are treated the same as shared ones

Modifications:
Use existing Recycler(s) on un-shared magazines to save expensive atomic operations while reusing adaptive buffers

Result:
Further improve netty#14279 for the common path i.e. event loops
@franz1981
franz1981 force-pushed the 4.1-mag-local-pool branch from 3e45566 to 35b1980 Compare November 11, 2024 10:02
normanmaurer
normanmaurer reviewed Nov 11, 2024
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
buf = new AdaptiveByteBuf(handle);
}
}
buf.resetRefCnt();

@normanmaurer normanmaurer Nov 11, 2024

Copy link
Copy Markdown
Member

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.

I guess its not a big deal but we could just not do this when we allocate a new buffer...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@franz1981 franz1981 Nov 11, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

most times we end-up reusing some (hopefully) - but I'm ok to move it in the right branch too, LMK

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@franz1981 franz1981 Nov 11, 2024

Copy link
Copy Markdown
Contributor Author

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.

Anyway is not using a volatile operation, but a lazySet AFAIK, which is way cheaper

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@franz1981
franz1981 merged commit 7b4fe3d into netty:4.1 Nov 11, 2024
franz1981 added a commit to franz1981/netty that referenced this pull request Nov 11, 2024
@franz1981
Specialize Adaptive's allocator Recycler based on magazine's owner (n…
633ef43
…etty#14421)

Motivation:
EventLoop local magazines are treated the same as shared ones

Modifications:
Use existing Recycler(s) on un-shared magazines to save expensive atomic
operations while reusing adaptive buffers

Result:
Further improve netty#14279 for the
common path i.e. event loops
normanmaurer pushed a commit that referenced this pull request Nov 12, 2024
@franz1981
Specialize Adaptive's allocator Recycler based on magazine's owner (#…
293931f
…14421) (#14454)

Motivation:
EventLoop local magazines are treated the same as shared ones

Modifications:
Use existing Recycler(s) on un-shared magazines to save expensive atomic
operations while reusing adaptive buffers

Result:
Further improve #14279 for the
common path i.e. event loops
This was referenced Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
cache failure 1233e4a5 #17565
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes
@chrisvest chrisvest chrisvest approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.115.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@franz1981 @chrisvest @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.