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 — Performance Degradation using AdaptiveByteBufAllocator · Issue #14272 · netty/netty

Performance Degradation using AdaptiveByteBufAllocator #14272

New issue
Copy link
New issue
Copy link
Closed
Closed
Performance Degradation using AdaptiveByteBufAllocator#14272
Copy link
Milestone
4.1.114.Final

Description

@ghost
ghost
opened on Sep 3, 2024

Expected behavior

According #13075, using AdaptiveByteBufAllocator should have performance improvement compared with default pooled allocator.

Actual behavior

The system throughput was much lower using AdaptiveByteBufAllocator, and we saw ZGC allocation stalls earlier.

Steps to reproduce

Run the same workload on the same application, just add the io.netty.allocator.type = adaptive system property, compare the system throughput.
Using default allocator:
We could reach 20K TPS and the system was very stable, no ZGC allocation stalls.
截屏2024-09-03 上午11 05 07
截屏2024-09-03 上午11 05 29
截屏2024-09-03 上午11 05 38
Using AdaptiveByteBufAllocator:
The system was not stable during the test, ZGC allocation stalls caused high CPU and response time which lower the throughput.
截屏2024-09-03 上午11 07 29
截屏2024-09-03 上午11 07 37
截屏2024-09-03 上午11 07 46
We have not found any suspicious events from JFRs or alloc profilings, but from heap dump, we saw the allocator related objects count was very different.
Using default allocator:
image
Using AdaptiveByteBufAllocator:
image
The questions is why AdaptiveByteBufAllocator caused high GC pressure and performance degradation, any tunings or configs could help to improve?

Minimal yet complete reproducer code (or URL to code)

Hard to provide

Netty version

<netty.version>4.1.112.Final</netty.version>
<netty-tcnative-boringssl-static.version>2.0.66.Final</netty-tcnative-boringssl-static.version>

JVM version (e.g. java -version)

openjdk version "17.0.11"

OS version (e.g. uname -a)

Linux 5.10.215-203.850.amzn2.x86_64

Activity

Next
  1. normanmaurer commented on Sep 3, 2024

    @normanmaurer
    normanmaurer
    on Sep 3, 2024
    Member
    More actions

    That's interesting... /cc @franz1981 @chrisvest

  2. franz1981 commented on Sep 3, 2024

    @franz1981
    franz1981
    on Sep 3, 2024
    Contributor
    More actions

    can you take an heap dump?

    I see few odd things:

    • large numbers of AdaptiveByteBufs: they should be GCd or contained in the Recycler's pools
    • large numbers of PooledNonRetainedSlicedByteBufs: it means your code is likely calling https://github.com/netty/netty/blob/4.1/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java#L1166C24-L1166C54 - is it accurate?
    • you seems to have an increased number of UnpooledUnsafeHeapByteBuf too - why it is increased? any idea?

    if there are more allocation stalls can you enable allocation profiling and share the JFRs here?
    according to
    https://sap.github.io/SapMachine/jfrevents/23.html#zallocationstall

    the ZGC allocation stalls "should" have a stack trace (I didn't checked) - if you share the JFR (with allocation profiling too) here it would help to better understand why such allocations are happening.
    The heap dump instead will help to check which chunks are actively used/the preferred chunk size per each etc etc

    While investigating on this, I've found #14273 FYI

  3. franz1981 commented on Sep 3, 2024

    @franz1981
    franz1981
    on Sep 3, 2024
    Contributor
    More actions

    @lsc1943 I see different problems there...

    1. I can see different allocators used
    2. the adaptive buffers allocated have no "handle" it means that they are not using any recycler i.e.
      image - which means that this code at

      netty/buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java

      Line 193 in c0fdb8e

      AdaptiveByteBuf buf = AdaptiveByteBuf.newInstance(willCleanupFastThreadLocals);
      is not using the recycler and keep on allocating new objects.

    I would check if you are requesting allocations from fast thread local(s) threads or not.

  4. He-Pin commented on Sep 4, 2024

    @He-Pin
    He-Pin
    on Sep 4, 2024
    Contributor
    More actions

    When using AdaptivePoolingAllocator, we encounter more Memory usage, so we switch back to the pooled one,but performance nearly the same in our case.

  5. normanmaurer commented on Sep 4, 2024

    @normanmaurer
    normanmaurer
    on Sep 4, 2024
    Member
    More actions

    @He-Pin could you open a new issue and give some more details there? This is kind of unexpected.

  6. franz1981 commented on Sep 4, 2024

    @franz1981
    franz1981
    on Sep 4, 2024
    Contributor
    More actions

    as @normanmaurer said @He-Pin : I remember we spoken about this already in another PR/issue (maybe in vertx?not sure..) - I suspect that @lsc1943 has an application which is not using FastThreadLocalThreads for the event loops, making FastThreadLocalThread.willCleanupFastThreadLocals(currentThread) to be false and NOT using pooled adaptive wrappers - and the same will likely happen with virtual threads - athough i have a slightly different solution for such, instead (will ping @chrisvest about it).

    Let's open a separate issue for your case, which i suppose is different

  7. linking12 commented on Sep 4, 2024

    @linking12
    linking12
    on Sep 4, 2024
    More actions

    as @normanmaurer said @He-Pin : I remember we spoken about this already in another PR/issue (maybe in vertx?not sure..) - I suspect that @lsc1943 has an application which is not using FastThreadLocalThreads for the event loops, making FastThreadLocalThread.willCleanupFastThreadLocals(currentThread) to be false and NOT using pooled adaptive wrappers - and the same will likely happen with virtual threads - athough i have a slightly different solution for such, instead (will ping @chrisvest about it).

    Let's open a separate issue for your case, which i suppose is different
    @franz1981 @normanmaurer

    @lsc1943 is our team member;
    you suspect may be right, let me clarify the thread model in our application;
    In fact, we are a proxy app, the thread model like this:
    image

    Is it because there is a bizThreadPool in the middle that causes FastThreadLocalThread to fail (ThreadId is not same? ), I cannot confirm whether this is the reason;

    Reacted by Francesco Nigro
  8. franz1981 commented on Sep 4, 2024

    @franz1981
    franz1981
    on Sep 4, 2024
    Contributor
    More actions

    I can tell for sure that the amount of garbage created come from there. I can def provide a sys prop to enable recyclers to work with non fast thread local threads (but than you will be on your own to remove such thread locals if the owner thread die...)

    I instead prefer the per magazine solution I have outlined instead, given that it bound the count to the magazines and not the threads - which under contention can be much larger

  9. normanmaurer commented on Sep 4, 2024

    @normanmaurer
    normanmaurer
    on Sep 4, 2024
    Member
    More actions

    @linking12 can you make your BizThreadPool and IoThreadPool use FastThreadLocalThread ? This could be done by using our DefaultThreadFactory for example. This should ensure the Recycler is used and so less GC is created.

  10. linking12 commented on Sep 4, 2024

    @linking12
    linking12
    on Sep 4, 2024
    More actions

    @linking12 can you make your BizThreadPool and IoThreadPool use FastThreadLocalThread ? This could be done by using our DefaultThreadFactory for example. This should ensure the Recycler is used and so less GC is created.

    let'e try;

    Reacted by Francesco Nigro
  11. linking12 commented on Sep 4, 2024

    @linking12
    linking12
    on Sep 4, 2024
    More actions

    DefaultThreadFactory
    @normanmaurer
    this is my stupid old code, although I realized I should use threadLocal as much as possible, but I didn't pay attention it
    🤣

  12. normanmaurer commented on Sep 4, 2024

    @normanmaurer
    normanmaurer
    on Sep 4, 2024
    Member
    More actions

    @linking12 haha... btw I its open source and you can point me to it I might also be able to have a look

    Reacted by linking12
  13. normanmaurer commented on Sep 5, 2024

    @normanmaurer
    normanmaurer
    on Sep 5, 2024
    Member
    More actions

    @lsc1943 thanks a lot for the feedback. Could you also compare the memory usage of both by any chance ? I would be interested to learn about the differences you see..

  14. dpy1123 commented on Sep 5, 2024

    @dpy1123
    dpy1123
    on Sep 5, 2024
    Contributor
    More actions

    @lsc1943 thanks a lot for the feedback. Could you also compare the memory usage of both by any chance ? I would be interested to learn about the differences you see..

    hi @normanmaurer, we're still in test stage, will provide you later.

    btw, we find 'refCnt:0' exceptions when using AdaptiveByteBufAllocator. If we using old school PooledBuf we don't see this problem.
    image
    I'm assuming this buf here is not 'resetRefCnt()' correctly. And we're now using FastThreadLocalThread.
    io.netty.buffer.AdaptivePoolingAllocator#allocate(int, int)
    image
    @franz1981 what do you think? is there anything we missing?

    Reacted by Francesco Nigro
  15. 34 remaining items

  16. linking12 commented on Sep 12, 2024

    @linking12
    linking12
    on Sep 12, 2024
    More actions

    @linking12 let us know how it goes...

    so far so good in our stress test environment(runed 2 hours), we need more time to verify is fixed

    Reacted by Norman Maurer and Chris Vest
  17. normanmaurer commented on Sep 12, 2024

    @normanmaurer
    normanmaurer
    on Sep 12, 2024
    Member
    More actions

    @linking12 once we are sure its fixed it would also be good to get another idea about the perf / memory usage with all the changes that we did put in.

  18. linking12 commented on Sep 12, 2024

    @linking12
    linking12
    on Sep 12, 2024
    More actions

    @linking12 once we are sure its fixed it would also be good to get another idea about the perf / memory usage with all the changes that we did put in.

    ok

  19. normanmaurer commented on Sep 12, 2024

    @normanmaurer
    normanmaurer
    on Sep 12, 2024
    Member
    More actions

    @linking12 still all good ?

  20. normanmaurer commented on Sep 13, 2024

    @normanmaurer
    normanmaurer
    on Sep 13, 2024
    Member
    More actions

    @linking12 @lsc1943 still all good ?

  21. normanmaurer commented on Sep 13, 2024

    @normanmaurer
    normanmaurer
    on Sep 13, 2024
    Member
    More actions

    Ok cool... let's close this one then.

  22. normanmaurer
    closed this as completedon Sep 13, 2024
  23. normanmaurer
    added this to the 4.1.114.Final milestone on Sep 13, 2024
  24. He-Pin commented on Sep 20, 2024

    @He-Pin
    He-Pin
    on Sep 20, 2024
    Contributor
    More actions

    @franz1981 Hi, I will reply you in detail tomorrow thanks for the ping.

    Reacted by Francesco Nigro
  25. normanmaurer commented on Oct 1, 2024

    @normanmaurer
    normanmaurer
    on Oct 1, 2024
    Member
    More actions

    @He-Pin any update ?

  26. syhily commented on May 30, 2025

    @syhily
    syhily
    on May 30, 2025
    More actions

    Hi all. After upgrading to netty 4.2, we soon meet same issue like this thread. The CPU usage increased a lot and the memory usage also increased.

    I think we should reopen this thread and do a further investigation.

  27. franz1981 commented on May 30, 2025

    @franz1981
    franz1981
    on May 30, 2025
    Contributor
    More actions

    we soon meet same issue like this thread

    We talked about few issues in this thread.
    Which one are you referring to?
    So:

    • make sure that you test the same exact. version (4.2) without the adaptive pool and got a better behaviour (if the issue persist check if is a leak, see Performance Degradation using AdaptiveByteBufAllocator #14272 (comment))
    • make sure to use the very latest 4.2
    • make sure to use all the required JVM args to allow your JDK version (which one?) to create buffers without cleaners and use Unsafe

    If with all of this, the problem is still there, provide heapdump or profiling data (allocation flamegraphs) which can help us to help you 🙏

    All of this, in a new issue, unless your issue is 1:1 with this

  28. syhily commented on May 30, 2025

    @syhily
    syhily
    on May 30, 2025
    More actions
    • make sure that you test the same exact. version (4.2) without the adaptive pool and got a better behaviour (if the issue persist check if is a leak, see Performance Degradation using AdaptiveByteBufAllocator #14272 (comment))

    Yep. We rollback to use pooled and the performance get slightly increased and is almost the same as the 4.1.199.

    Package AVG CPU Usage QPS
    4.2.1 io.netty.allocator.type=adaptive ~400%(4core) ~450/s
    4.1.199 io.netty.allocator.type=pooled ~250% ~590/s
    4.2.1 io.netty.allocator.type=pooled ~220% ~530/s
    • make sure to use the very latest 4.2

    Yep. We are using Netty 4.2.1

    • make sure to use all the required JVM args to allow your JDK version (which one?) to create buffers without cleaners and use Unsafe

    We are using JDK 17 and the Unsafe is enabled.

    If with all of this, the problem is still there, provide heapdump or profiling data (allocation flamegraphs) which can help us to help you 🙏

    Here are two flame graph on using Netty 4.1.199 and Netty 4.2.1. You can see a slight impact on adaptive allocator. The JDK version is 17 without any args related to Netty. But the Unsafe is enabled.

    4.1.199.html.zip

    4.2.1.html.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.114.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.