Skip to content

Change default of io.netty.allocator.useCacheForAllThreads to false - #12109

Merged
normanmaurer merged 1 commit into
netty:4.1from
chrisvest:41-backport-no-cache-all-threads
Mar 3, 2022
Merged

normanmaurer merged 1 commit into
netty:4.1from
chrisvest:41-backport-no-cache-all-threads

Conversation

@chrisvest

@chrisvest chrisvest commented Feb 17, 2022 •

Copy link
Copy Markdown
Member

This is a back port of #8991

Motivation:

We currently use a thread local cache for all threads which often is suprising to users as it may result in a lot of memory usage if they allocate buffers from outside the EventLoop in different threads. We should better not do this by default to keep suprises to a minimum. Users that need the performance and know what they are doing can still change this.

Modifications:

Change io.netty.allocator.useCacheForAllThreads to false by default

Result:

Related to #8536.
This should also mitigate (but not solve) #12067

@normanmaurer

Copy link
Copy Markdown
Member

I think this is a good one...We should ensure we explicit call this out in the release notes tho!

@franz1981 franz1981 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm the one proposing this to @chrisvest , hence +1 by me

@mostroverkhov

Copy link
Copy Markdown
Contributor

This is breaking change for 4.1 branch, isn't It?
Particularly painful for libraries as there is no adequate programmatic control over default allocator (which is configured with system properties). The patch would at least affect RPCs performance which often cant enforce threads where messages are created.

@chrisvest

Copy link
Copy Markdown
Member Author

It's a non-functional change, so I don't consider it breaking. Downstream libraries and frameworks should allow resource hubs, such as allocators, to be passed in, but it's beyond our control if they do this. And those that shade Netty control their own fate either way. For the time being, it seems like the current default has caused trouble, so we're trying this change.

@mostroverkhov

mostroverkhov commented Feb 21, 2022 •

Copy link
Copy Markdown
Contributor

It's a non-functional change, so I don't consider it breaking.

It does flip the default (existed for 5 years) - so considerable portion of buffers allocated by pooled BytebufAllocator become non-pooled.

it seems like the current default has caused trouble

This may be non-representative - few complained (they may use another constructor), but thousands rely on current default.

This change would affect downstream libraries regardless shading - as library accepting allocator in API cant force end user not to use this new (proposed) default, and new default affects performance in negative way.

@franz1981

franz1981 commented Feb 21, 2022 •

Copy link
Copy Markdown
Contributor

@mostroverkhov

so considerable portion of buffers allocated by pooled BytebufAllocator become non-pooled.

It's not how it works: It means that allocation won't use thread-local allocation buffers, but can fall into many other shared layers of pools (the jemalloc 3 doc explain it quite well).

@hyperxpro

Copy link
Copy Markdown
Contributor

It's a non-functional change, so I don't consider it breaking. Downstream libraries and frameworks should allow resource hubs, such as allocators, to be passed in, but it's beyond our control if they do this. And those that shade Netty control their own fate either way. For the time being, it seems like the current default has caused trouble, so we're trying this change.

I think we should announce this change in release notes upon release.

@normanmaurer

Copy link
Copy Markdown
Member

It's a non-functional change, so I don't consider it breaking. Downstream libraries and frameworks should allow resource hubs, such as allocators, to be passed in, but it's beyond our control if they do this. And those that shade Netty control their own fate either way. For the time being, it seems like the current default has caused trouble, so we're trying this change.

I think we should announce this change in release notes upon release.

yep... thats why I added the label important.

@normanmaurer

Copy link
Copy Markdown
Member

@chrisvest can you rebase and resolve the conflicts please.

…etty#8991)

Motivation:

We currently use a thread local cache for all threads which often is suprising to users as it may result in a lot of memory usage if they allocate buffers from outside the EventLoop in different threads.
We should better not do this by default to keep suprises to a minimum.
Users that need the performance and know what they are doing can still change this.

Modifications:

Change io.netty.allocator.useCacheForAllThreads to false by default

Result:

Related to netty#8536.
@chrisvest
chrisvest force-pushed the 41-backport-no-cache-all-threads branch from 8e3f500 to cbac543 Compare February 28, 2022 23:29
@chrisvest

Copy link
Copy Markdown
Member Author

@normanmaurer Rebased

@normanmaurer

Copy link
Copy Markdown
Member

@mostroverkhov thanks for bringing up your concerns but I still think this is a worthwhile change (even for 4.1). Like said by @franz1981 the pooling will still work it will just remove the "thread local caches" for the "other threads" by default.

@normanmaurer
normanmaurer merged commit 4797b88 into netty:4.1 Mar 3, 2022
@chrisvest
chrisvest deleted the 41-backport-no-cache-all-threads branch March 3, 2022 18:22
@gemmellr

gemmellr commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

For documenting the change of behaviour for this: it would also seem to affect the EventLoop thread as well (as opposed to just 'other threads') for anyone supplying a ThreadFactory when creating the EventLoopGroup if it is not creating a FastThreadLocalThread specifically.

https://github.com/netty/netty/blob/netty-4.1.74.Final/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java#L514

(Originally mentioned elsewhere by @franz1981)

normanmaurer added a commit that referenced this pull request Mar 9, 2022
…utor by default

Motivation:

#12109 changed the default of using the thread local cache for buffers only for FastThreadLocalThread. While this is good it also means that it would affect everyone that use a custom ThreadFactory when construct the EventLoop / EventExecutor

Modifications:

Make use of ThreadExecutorMap to check if the Thread is used by any EventExecutor and if so also enable the cache.

Result:

Fixes #12109 (comment)
@normanmaurer

Copy link
Copy Markdown
Member

@gemmellr good point! thanks for bringing it up... This should fix it: #12158

chrisvest pushed a commit that referenced this pull request Mar 9, 2022
…utor by default (#12158)

Motivation:

#12109 changed the default of using the thread local cache for buffers only for FastThreadLocalThread. While this is good it also means that it would affect everyone that use a custom ThreadFactory when construct the EventLoop / EventExecutor

Modifications:

Make use of ThreadExecutorMap to check if the Thread is used by any EventExecutor and if so also enable the cache.

Result:

Fixes #12109 (comment)
chrisvest pushed a commit that referenced this pull request Mar 9, 2022
…utor by default (#12158)

Motivation:

#12109 changed the default of using the thread local cache for buffers only for FastThreadLocalThread. While this is good it also means that it would affect everyone that use a custom ThreadFactory when construct the EventLoop / EventExecutor

Modifications:

Make use of ThreadExecutorMap to check if the Thread is used by any EventExecutor and if so also enable the cache.

Result:

Fixes #12109 (comment)
srowen pushed a commit to apache/spark that referenced this pull request Mar 19, 2022
### What changes were proposed in this pull request?
This pr aims to upgrade netty to 4.1.75 and this pr add the explicit dependency on `netty-tcnative-classes` because the dependency on `netty-tcnative-classes` is changed to `Optional` in [netty](netty/netty#12146).

### Why are the changes needed?
The release notes as follows:

- https://netty.io/news/2022/03/10/4-1-75-Final.html

There are 2 import changes in this version and both of these changes are to reduce memory-overhead:

- [Reduce the default PooledByteBufAllocator chunk size from 16 MiB to 4 MiB](netty/netty#12108)
- [Change default of io.netty.allocator.useCacheForAllThreads to false](netty/netty#12109)

### Does this PR introduce _any_ user-facing change?
Yes, all changes are caused by the change of Netty.
If the user wants to maintain the same behavior as the previous version, the user needs to make the following configuration:

- add `-Dio.netty.allocator.useCacheForAllThreads=true` to enable `useCacheForAllThreads `
- add `-Dio.netty.allocator.maxOrder=11` to keep the chunk size of `PooledByteBufAllocator` to 16m

### How was this patch tested?
Pass GA

Closes #35835 from LuciferYang/upgrade-netty-4175.

Authored-by: yangjie01 <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
raidyue pushed a commit to raidyue/netty that referenced this pull request Jul 8, 2022
…etty#8991) (netty#12109)

Motivation:

We currently use a thread local cache for all threads which often is suprising to users as it may result in a lot of memory usage if they allocate buffers from outside the EventLoop in different threads.
We should better not do this by default to keep suprises to a minimum.
Users that need the performance and know what they are doing can still change this.

Modifications:

Change io.netty.allocator.useCacheForAllThreads to false by default

Result:

Related to netty#8536.

Co-authored-by: Norman Maurer <[email protected]>
raidyue pushed a commit to raidyue/netty that referenced this pull request Jul 8, 2022
…utor by default (netty#12158)

Motivation:

netty#12109 changed the default of using the thread local cache for buffers only for FastThreadLocalThread. While this is good it also means that it would affect everyone that use a custom ThreadFactory when construct the EventLoop / EventExecutor

Modifications:

Make use of ThreadExecutorMap to check if the Thread is used by any EventExecutor and if so also enable the cache.

Result:

Fixes netty#12109 (comment)
franz1981 pushed a commit to franz1981/netty that referenced this pull request Aug 22, 2022
…etty#8991) (netty#12109)

Motivation:

We currently use a thread local cache for all threads which often is suprising to users as it may result in a lot of memory usage if they allocate buffers from outside the EventLoop in different threads.
We should better not do this by default to keep suprises to a minimum.
Users that need the performance and know what they are doing can still change this.

Modifications:

Change io.netty.allocator.useCacheForAllThreads to false by default

Result:

Related to netty#8536.

Co-authored-by: Norman Maurer <[email protected]>
franz1981 pushed a commit to franz1981/netty that referenced this pull request Aug 22, 2022
…utor by default (netty#12158)

Motivation:

netty#12109 changed the default of using the thread local cache for buffers only for FastThreadLocalThread. While this is good it also means that it would affect everyone that use a custom ThreadFactory when construct the EventLoop / EventExecutor

Modifications:

Make use of ThreadExecutorMap to check if the Thread is used by any EventExecutor and if so also enable the cache.

Result:

Fixes netty#12109 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants