Skip to content

update default value of allocatorPoolingConcurrency#3001

Merged
hangc0276 merged 1 commit intoapache:masterfrom
sunshujie1990:master
Jul 27, 2022
Merged

update default value of allocatorPoolingConcurrency#3001
hangc0276 merged 1 commit intoapache:masterfrom
sunshujie1990:master

Conversation

@sunshujie1990
Copy link
Copy Markdown
Contributor

Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:

Motivation

The default value of allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator.

Assume:
40 processors
80 arena (processors2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80
2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.

Changes

Use Netty default arena num PooledByteBufAllocator.defaultNumDirectArena() as default allocatorPoolingConcurrency.

Set a more reasonable default value to avoid OutOfDirectMemoryError.
@sunshujie1990
Copy link
Copy Markdown
Contributor Author

@eolivelli Please help to review it.

*/
public int getAllocatorPoolingConcurrency() {
return this.getInteger(ALLOCATOR_POOLING_CONCURRENCY, 2 * Runtime.getRuntime().availableProcessors());
return this.getInteger(ALLOCATOR_POOLING_CONCURRENCY, PooledByteBufAllocator.defaultNumDirectArena());
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.

Copy link
Copy Markdown
Contributor Author

@sunshujie1990 sunshujie1990 Jun 25, 2022

Choose a reason for hiding this comment

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

The default value of defaultNumDirectArena is 2 * cpus https://github.com/netty/netty/blob/4e439264df0523fb6efce5f8f6c7c7fa74addd07/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java#L413-L418

Thanks for your reply. Netty default value use the min value between 2*cpus and max mem defaultChunkSize / 2 / 3 to avoid oom. And it helps me resolved bookeeper oom problem in my product environment. Can you help me to merge it?

        DEFAULT_NUM_DIRECT_ARENA = Math.max(0,
                SystemPropertyUtil.getInt(
                        "io.netty.allocator.numDirectArenas",
                        (int) Math.min(
                                defaultMinNumArena,
                                PlatformDependent.maxDirectMemory() / defaultChunkSize / 2 / 3)));

@hangc0276
Copy link
Copy Markdown
Contributor

ping @merlimat @eolivelli @dlg99, Would you please help take a look? thanks.

Copy link
Copy Markdown
Member

@horizonzy horizonzy left a comment

Choose a reason for hiding this comment

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

Nice catch! It happend at low maxDirectMemory.

@horizonzy
Copy link
Copy Markdown
Member

And there is a more suitable value for it.

In we use DbLedgerStorage, it will occupy 1/2 unpooled direct memory for write cache and read cache, it's unpooled but occupy direct memory, we shuold consider it.

When we calculate the concurrency, we should subtract the memory which writeCache and readCache total occupy.

See:

long writeCacheMaxSize = getLongVariableOrDefault(conf, WRITE_CACHE_MAX_SIZE_MB,
DEFAULT_WRITE_CACHE_MAX_SIZE_MB) * MB;
long readCacheMaxSize = getLongVariableOrDefault(conf, READ_AHEAD_CACHE_MAX_SIZE_MB,
DEFAULT_READ_CACHE_MAX_SIZE_MB) * MB;
.

cacheSegments[segmentsCount - 1] = Unpooled.directBuffer(lastSegmentSize, lastSegmentSize);

cacheSegments.add(Unpooled.directBuffer(segmentSize, segmentSize));

@hangc0276
Copy link
Copy Markdown
Contributor

ping @sunshujie1990, would you please take a look at the last comment?

@sunshujie1990
Copy link
Copy Markdown
Contributor Author

ping @sunshujie1990, would you please take a look at the last comment?

sure

Copy link
Copy Markdown
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

lgtm

@StevenLuMT
Copy link
Copy Markdown
Member

if no problem, please merge it,thanks @eolivelli @dlg99 @hangc0276

@hangc0276 hangc0276 merged commit 01c8824 into apache:master Jul 27, 2022
zymap pushed a commit that referenced this pull request Oct 26, 2022
Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:

### Motivation
The default value of  allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator.

Assume:
40 processors
80 arena (processors*2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80*2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.

### Changes
Use Netty default arena num `PooledByteBufAllocator.defaultNumDirectArena()` as default allocatorPoolingConcurrency.

(cherry picked from commit 01c8824)
hangc0276 pushed a commit to hangc0276/bookkeeper that referenced this pull request Nov 7, 2022
Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:

### Motivation
The default value of  allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator.

Assume:
40 processors
80 arena (processors*2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80*2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.

### Changes
Use Netty default arena num `PooledByteBufAllocator.defaultNumDirectArena()` as default allocatorPoolingConcurrency.

(cherry picked from commit 01c8824)
hangc0276 pushed a commit to hangc0276/bookkeeper that referenced this pull request Nov 7, 2022
Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:

### Motivation
The default value of  allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator.

Assume:
40 processors
80 arena (processors*2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80*2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.

### Changes
Use Netty default arena num `PooledByteBufAllocator.defaultNumDirectArena()` as default allocatorPoolingConcurrency.

(cherry picked from commit 01c8824)
nicoloboschi pushed a commit to datastax/bookkeeper that referenced this pull request Jan 11, 2023
Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:

### Motivation
The default value of  allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator.

Assume:
40 processors
80 arena (processors*2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80*2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.

### Changes
Use Netty default arena num `PooledByteBufAllocator.defaultNumDirectArena()` as default allocatorPoolingConcurrency.

(cherry picked from commit 01c8824)
(cherry picked from commit 35d0ecf)
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
Set a more reasonable default value to avoid OutOfDirectMemoryError.

Descriptions of the changes in this PR:


### Motivation
The default value of  allocatorPoolingConcurrency is 2 * Runtime.getRuntime().availableProcessors(). It's used to specify the num of Arena in PooledByteBufAllocator. 

Assume:
40 processors
80 arena (processors*2)
2 chunk per arena
16MiB per chunk
JVM's total direct mem should be larger then 80*2*16=2560MiB, otherwise OutOfDirectMemoryError occured.

OutOfDirectMemoryError much more likely to occur in Docker, cause JDK versions earlier than Java SE 8U131 does not support Docker CPU limits.


### Changes
Use Netty default arena num `PooledByteBufAllocator.defaultNumDirectArena()` as default allocatorPoolingConcurrency.
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.

7 participants