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 — Performance Degradation using AdaptiveByteBufAllocator · Issue #14272 · netty/netty Closed Milestone DescriptionExpected behaviorAccording #13075, using AdaptiveByteBufAllocator should have performance improvement compared with default pooled allocator. Actual behaviorThe system throughput was much lower using AdaptiveByteBufAllocator, and we saw ZGC allocation stalls earlier. Steps to reproduceRun the same workload on the same application, just add the io.netty.allocator.type = adaptive system property, compare the system throughput. Minimal yet complete reproducer code (or URL to code)Hard to provide Netty version<netty.version>4.1.112.Final</netty.version> JVM version (e.g.
|
| AdaptiveByteBuf buf = AdaptiveByteBuf.newInstance(willCleanupFastThreadLocals); |
I would check if you are requesting allocations from fast thread local(s) threads or not.
When using AdaptivePoolingAllocator, we encounter more Memory usage, so we switch back to the pooled one,but performance nearly the same in our case.
@He-Pin could you open a new issue and give some more details there? This is kind of unexpected.
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
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, makingFastThreadLocalThread.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:

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;
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
@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.
@linking12 can you make your
BizThreadPoolandIoThreadPooluseFastThreadLocalThread? This could be done by using ourDefaultThreadFactoryfor example. This should ensure theRecycleris used and so less GC is created.
let'e try;
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
🤣
@linking12 haha... btw I its open source and you can point me to it I might also be able to have a look
@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..
@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.

I'm assuming this buf here is not 'resetRefCnt()' correctly. And we're now using FastThreadLocalThread.
io.netty.buffer.AdaptivePoolingAllocator#allocate(int, int)

@franz1981 what do you think? is there anything we missing?
@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
@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.
@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
@linking12 still all good ?
@linking12 @lsc1943 still all good ?
Ok cool... let's close this one then.
@franz1981 Hi, I will reply you in detail tomorrow thanks for the ping.
@He-Pin any update ?
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.
we soon meet same issue like this thread
We talked about few issues in this thread.
Which one are you referring to?
So:
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
- 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.