SteNicholas commented on code in PR #3625:
URL: https://github.com/apache/celeborn/pull/3625#discussion_r2924006729
##########
common/src/main/java/org/apache/celeborn/common/network/util/NettyUtils.java:
##########
@@ -141,23 +142,32 @@ public static String getRemoteAddress(Channel channel) {
* effect for PooledByteBufAllocator.
*/
private static ByteBufAllocator createByteBufAllocator(
- boolean pooled, boolean allowDirectBufs, boolean allowCache, int
numCores) {
- if (pooled) {
- if (numCores == 0) {
- numCores = Runtime.getRuntime().availableProcessors();
- }
- return new PooledByteBufAllocator(
- allowDirectBufs && PlatformDependent.directBufferPreferred(),
- Math.min(PooledByteBufAllocator.defaultNumHeapArena(), numCores),
- Math.min(PooledByteBufAllocator.defaultNumDirectArena(),
allowDirectBufs ? numCores : 0),
- PooledByteBufAllocator.defaultPageSize(),
- PooledByteBufAllocator.defaultMaxOrder(),
- allowCache ? PooledByteBufAllocator.defaultSmallCacheSize() : 0,
- allowCache ? PooledByteBufAllocator.defaultNormalCacheSize() : 0,
- allowCache && PooledByteBufAllocator.defaultUseCacheForAllThreads());
- } else {
- return new UnpooledByteBufAllocator(
- allowDirectBufs && PlatformDependent.directBufferPreferred());
+ NettyMemoryAllocatorType allocatorType,
+ boolean allowDirectBufs,
+ boolean allowCache,
+ int numCores) {
+ boolean preferDirect = allowDirectBufs &&
PlatformDependent.directBufferPreferred();
+ switch (allocatorType) {
+ case POOLED:
+ if (numCores == 0) {
+ numCores = Runtime.getRuntime().availableProcessors();
+ }
+ return new PooledByteBufAllocator(
+ preferDirect,
+ Math.min(PooledByteBufAllocator.defaultNumHeapArena(), numCores),
+ Math.min(
+ PooledByteBufAllocator.defaultNumDirectArena(),
allowDirectBufs ? numCores : 0),
+ PooledByteBufAllocator.defaultPageSize(),
+ PooledByteBufAllocator.defaultMaxOrder(),
+ allowCache ? PooledByteBufAllocator.defaultSmallCacheSize() : 0,
+ allowCache ? PooledByteBufAllocator.defaultNormalCacheSize() : 0,
+ allowCache &&
PooledByteBufAllocator.defaultUseCacheForAllThreads());
+ case UNPOOLED:
+ return new UnpooledByteBufAllocator(preferDirect);
+ case ADAPTIVE:
+ return new AdaptiveByteBufAllocator(preferDirect);
Review Comment:
@pan3793,
[`AdaptiveByteBufAllocator`](https://github.com/netty/netty/blob/4.2/buffer/src/main/java/io/netty/buffer/AdaptiveByteBufAllocator.java)
supports `useCacheForNonEventLoopThreads`, which does not support in this pull
request. This pull request only supports the common argument `preferDirect`,
which aligins wth the support of `UnpooledByteBufAllocator`. PTAL.
```
public final class AdaptiveByteBufAllocator extends AbstractByteBufAllocator
implements ByteBufAllocatorMetricProvider, ByteBufAllocatorMetric {
private static final boolean
DEFAULT_USE_CACHED_MAGAZINES_FOR_NON_EVENT_LOOP_THREADS;
static {
DEFAULT_USE_CACHED_MAGAZINES_FOR_NON_EVENT_LOOP_THREADS =
SystemPropertyUtil.getBoolean(
"io.netty.allocator.useCachedMagazinesForNonEventLoopThreads", false);
logger.debug("-Dio.netty.allocator.useCachedMagazinesForNonEventLoopThreads:
{}",
DEFAULT_USE_CACHED_MAGAZINES_FOR_NON_EVENT_LOOP_THREADS);
}
private final AdaptivePoolingAllocator direct;
private final AdaptivePoolingAllocator heap;
public AdaptiveByteBufAllocator() {
this(!PlatformDependent.isExplicitNoPreferDirect());
}
public AdaptiveByteBufAllocator(boolean preferDirect) {
this(preferDirect,
DEFAULT_USE_CACHED_MAGAZINES_FOR_NON_EVENT_LOOP_THREADS);
}
public AdaptiveByteBufAllocator(boolean preferDirect, boolean
useCacheForNonEventLoopThreads) {
super(preferDirect);
direct = new AdaptivePoolingAllocator(new
DirectChunkAllocator(this), useCacheForNonEventLoopThreads);
heap = new AdaptivePoolingAllocator(new HeapChunkAllocator(this),
useCacheForNonEventLoopThreads);
}
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]