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 — Allocate bytebuf without magazine lock when threads get collisions by laosijikaichele · Pull Request #14594 · netty/netty

Conversation

@laosijikaichele

@laosijikaichele laosijikaichele commented Dec 17, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR continued from #14534 which was mis-closed.

Sorry, something went wrong.

Uh oh!

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

All reactions
laosijikaichele
Allocate bytebuf without magazine lock when threads get collisions
31b6ac6
@laosijikaichele laosijikaichele mentioned this pull request Dec 17, 2024
Allocate bytebuf without magazine lock when threads get collisions #14534
Closed
@laosijikaichele

laosijikaichele commented Dec 18, 2024

Copy link
Copy Markdown
Contributor Author

The computer's MAX_STRIPES value is 16, the benchmark class: AdaptiveByteBufAllocatorConcurrentNoCacheBenchmark which uses 32 threads on the benchmark method(@Threads(32)).

JMH results comparison between 4.1-branch and current PR: jmh.morethan

Overall, the current PR has around 15% ~ 43% performance improvements:

截屏2024-12-18 上午11 17 38
inemtsev reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Dec 20, 2024

Copy link
Copy Markdown
Member

@laosijikaichele while the numbers look good in general I wonder if it might also cause more churn (and fragmentation) in general as we might not be able to full the "current" chunk before trying to use the nextInLine or the central queue.

He-Pin and laosijikaichele reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer requested review from franz1981 and normanmaurer December 20, 2024 08:28
@franz1981

franz1981 commented Dec 20, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

I shared the same exact concerns as @normanmaurer in the previous pr (although not so clearly explained, so sorry for that...) since we use the chunk for a single allocation - I'll check today if I can get some cycles to work on this

All reactions

Sorry, something went wrong.

Uh oh!

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

@He-Pin

He-Pin commented Dec 20, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

will it cause OOM with long time stress testing ?@laosijikaichele ,eg 2 days

All reactions

Sorry, something went wrong.

Uh oh!

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

@laosijikaichele

laosijikaichele commented Dec 20, 2024

Copy link
Copy Markdown
Contributor Author

@laosijikaichele while the numbers look good in general I wonder if it might also cause more churn (and fragmentation) in general as we might not be able to full the "current" chunk before trying to use the nextInLine or the central queue.

This PR mainly focused on the thread collision cases when multiple threads get raced on the same magazine, which means it only take effect when the thread collision happens, at that moment, the priority of reducing the race condition becomes more important than for example 'fragmentation' concern, IMHO.

In addition, based on the previous benchmark, it seems complement the sudden performance downgrade for some size allocations(when size is 123456), please refer: size-123456-performance.

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981

franz1981 commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

@laosijikaichele

it seems complement the sudden performance downgrade for some size allocations(when size is 123456), please refer

this is still happening? I remember a fix from @normanmaurer which could affect such

All reactions

Sorry, something went wrong.

Uh oh!

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

@laosijikaichele

laosijikaichele commented Dec 20, 2024

Copy link
Copy Markdown
Contributor Author

@laosijikaichele

it seems complement the sudden performance downgrade for some size allocations(when size is 123456), please refer

this is still happening? I remember a fix from @normanmaurer which could affect such

I have not checked it recently.

Just now have done a quick benchmark for current 4.1-branch and current-PR:

  1. 4.1-branch:
Benchmark                     (size)   (tokens)  Mode  Cnt      Score             Error  Units
allocateReleaseHeapAdaptive    12345         0  thrpt    3  41752087.146 ± 39592438.639  ops/s
allocateReleaseHeapAdaptive   123456         0  thrpt    3  36162110.480 ±  1743823.506  ops/s
allocateReleaseHeapAdaptive  1234567         0  thrpt    3  36652755.266 ± 21082415.345  ops/s
  1. current-PR:

Benchmark                     (size)   (tokens)  Mode  Cnt      Score             Error  Units
allocateReleaseHeapAdaptive    12345         0  thrpt    3  62951072.371 ± 111061461.772  ops/s
allocateReleaseHeapAdaptive   123456         0  thrpt    3  75473091.228 ±   3817135.013  ops/s
allocateReleaseHeapAdaptive  1234567         0  thrpt    3  53722678.819 ±  53842106.833  ops/s

@franz1981
Seems the sudden downgrade issue not reproduced this time, but the current-PR performance still about 2 times than 4.1-branch when size is 123456.

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981

franz1981 commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

Seems the sudden downgrade issue not reproduced this time

We should profile -prof gc to make sure of it; but in case it is not reproducible I believe is due to @normanmaurer changes

All reactions

Sorry, something went wrong.

Uh oh!

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

@laosijikaichele

laosijikaichele commented Dec 20, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

will it cause OOM with long time stress testing ?@laosijikaichele ,eg 2 days

I think this PR is unrelated to the OOM issue. But it will be better if we have a chance to do a long time stress testing to see the memory effect. I will try to figure a way to do it when have some time.

All reactions

Sorry, something went wrong.

Uh oh!

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

normanmaurer
normanmaurer approved these changes Dec 21, 2024
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

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

@normanmaurer
Update buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.…
d439a71
…java
normanmaurer
normanmaurer reviewed Dec 21, 2024
View reviewed changes
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Resolved

Uh oh!

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

@normanmaurer
Update buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.…
6aaa26f
…java
@laosijikaichele

laosijikaichele commented Dec 22, 2024

Copy link
Copy Markdown
Contributor Author

Just popped up an idea, we also can make the calling to 'allocateWithoutLock' switchable, which means if the 'adaptive' is in an 'eager' mode, it will call 'allocateWithoutLock' when thread collisions happened, otherwise it will continue to loop. This can be done by add a simple configurable Boolean flag.

All reactions

Sorry, something went wrong.

Uh oh!

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

@laosijikaichele

laosijikaichele commented Dec 22, 2024

Copy link
Copy Markdown
Contributor Author

Done a benchmark to cover more 'size' cases, which uses 123 as the increased step size, and the size range is [123 byte - 13284 byte], using this benchmark code, and set 32 threads @threads(32) on the benchmark method to let the thread collision easily happen, the AdaptivePoolingAllocator.MAX_STRIPES is 16 on the test computer, the java version is JDK-17.

The comparison results between '4.1-branch' and this PR: jmh-morethan

The results summary:
截屏2024-12-23 上午1 09 38

I may do more benchmarks to cover more 'size' cases this week, if have some time.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Jan 13, 2025

Copy link
Copy Markdown
Member

@franz1981 did you have time to look into this one ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@franz1981

franz1981 commented Jan 13, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@normanmaurer not yet, hope these days or max next week 🙏

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Jan 13, 2025

Copy link
Copy Markdown
Member

@normanmaurer not yet, hope these days or max next week 🙏

@franz1981 nice… keep me posted please

All reactions

Sorry, something went wrong.

Uh oh!

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

franz1981
franz1981 approved these changes Jan 24, 2025
View reviewed changes

@franz1981 franz1981 left a comment

Copy link
Copy Markdown
Contributor

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.

The change per se looks good since it allows some progress, instead of just spinning.
What's good thou is that it still try to be somehow "local" to the preferred magazine, trying the others as last resort.

I haven't yet been able to reproduce your numbers (with the same degree of success) - but is more due to unstable machines on my side - hope tomorrow to give it a spin in the lab.

Separate question: what do you think about adding a configuration benchmark parameter like

    @Benchmark
    @Threads(32)
    public boolean allocateReleaseHeapAdaptive() {
        ByteBuf buf = adaptiveAllocator.heapBuffer(size);
        // this is useful to capture the case where a buffer is stolen
        // from too many other threads which already own it, since the RWO requires
        // bringing it in the local cache and invalidate other caches - if shared
        if (writeBuffer) {
            buf.setZero(0, size);
        }
        return buf.release();
    }

since it should help to account for cases in which the allocator is better to keep local allocations, since that writing the buffer, in case has been shared with others cores, will likely cause additional cache coherency traffic.
Hopefully, writing such a small buffer (we can decide to always write no more than 128 bytes, regardless the allocation size) won't impact the ability to highly contend while allocating.

Sorry, something went wrong.

Uh oh!

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

laosijikaichele reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@franz1981
franz1981 merged commit c29f4a5 into netty:4.1 Jan 24, 2025
@normanmaurer normanmaurer added this to the 4.1.118.Final milestone Jan 24, 2025
@laosijikaichele

laosijikaichele commented Jan 24, 2025

Copy link
Copy Markdown
Contributor Author

Separate question: what do you think about adding a configuration benchmark parameter like

    @Benchmark
    @Threads(32)
    public boolean allocateReleaseHeapAdaptive() {
        ByteBuf buf = adaptiveAllocator.heapBuffer(size);
        // this is useful to capture the case where a buffer is stolen
        // from too many other threads which already own it, since the RWO requires
        // bringing it in the local cache and invalidate other caches - if shared
        if (writeBuffer) {
            buf.setZero(0, size);
        }
        return buf.release();
    }

since it should help to account for cases in which the allocator is better to keep local allocations, since that writing the buffer, in case has been shared with others cores, will likely cause additional cache coherency traffic. Hopefully, writing such a small buffer (we can decide to always write no more than 128 bytes, regardless the allocation size) won't impact the ability to highly contend while allocating.

Sorry, I don't quite understand it, would you please share the full JMH test code, to let me better understand it?

All reactions

Sorry, something went wrong.

Uh oh!

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

franz1981 pushed a commit to franz1981/netty that referenced this pull request Jan 24, 2025
@laosijikaichele @normanmaurer @franz1981
Allocate bytebuf without magazine lock when threads get collisions (n…
4ad7157
…etty#14594)

This PR continued from netty#14534 which
was mis-closed.

---------

Co-authored-by: laosijikaichele <laosijikaichele>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Jan 28, 2025
@franz1981 @laosijikaichele @normanmaurer
Allocate bytebuf without magazine lock when threads get collisions (#…
8f81927
…14594) (#14729)

This PR continued from #14534 which
was mis-closed.

Co-authored-by: old driver <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@laosijikaichele laosijikaichele mentioned this pull request Feb 2, 2025
Adaptive pool false-sharing #14757
Open
@normanmaurer normanmaurer mentioned this pull request Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
@normanmaurer normanmaurer mentioned this pull request Sep 21, 2026
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
@franz1981 franz1981 franz1981 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.118.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@laosijikaichele @normanmaurer @franz1981 @He-Pin
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.