-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CELEBORN-1815] Support UnpooledByteBufAllocator #3043
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.buffer.PooledByteBufAllocator; | ||
import io.netty.buffer.UnpooledByteBufAllocator; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.EventLoopGroup; | ||
import io.netty.channel.ServerChannel; | ||
|
@@ -42,9 +44,8 @@ | |
|
||
/** Utilities for creating various Netty constructs based on whether we're using EPOLL or NIO. */ | ||
public class NettyUtils { | ||
private static final PooledByteBufAllocator[] _sharedPooledByteBufAllocator = | ||
new PooledByteBufAllocator[2]; | ||
private static ConcurrentHashMap<String, Integer> allocatorsIndex = | ||
private static final ByteBufAllocator[] _sharedByteBufAllocator = new ByteBufAllocator[2]; | ||
private static final ConcurrentHashMap<String, Integer> allocatorsIndex = | ||
JavaUtils.newConcurrentHashMap(); | ||
/** Creates a new ThreadFactory which prefixes each thread with the given name. */ | ||
public static ThreadFactory createThreadFactory(String threadPoolPrefix) { | ||
|
@@ -103,53 +104,59 @@ public static String getRemoteAddress(Channel channel) { | |
* released by the executor thread rather than the event loop thread. Those thread-local caches | ||
* actually delay the recycling of buffers, leading to larger memory usage. | ||
*/ | ||
private static PooledByteBufAllocator createPooledByteBufAllocator( | ||
boolean allowDirectBufs, boolean allowCache, int numCores) { | ||
if (numCores == 0) { | ||
numCores = Runtime.getRuntime().availableProcessors(); | ||
private static ByteBufAllocator createByteBufAllocator( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method comments should also be updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update: move the existing comment to the caller side, add new comments to explain each parameters |
||
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()); | ||
} | ||
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()); | ||
} | ||
|
||
/** | ||
* Returns the lazily created shared pooled ByteBuf allocator for the specified allowCache | ||
* parameter value. | ||
*/ | ||
public static synchronized PooledByteBufAllocator getSharedPooledByteBufAllocator( | ||
public static synchronized ByteBufAllocator getSharedByteBufAllocator( | ||
CelebornConf conf, AbstractSource source, boolean allowCache) { | ||
final int index = allowCache ? 0 : 1; | ||
if (_sharedPooledByteBufAllocator[index] == null) { | ||
_sharedPooledByteBufAllocator[index] = | ||
createPooledByteBufAllocator(true, allowCache, conf.networkAllocatorArenas()); | ||
if (_sharedByteBufAllocator[index] == null) { | ||
_sharedByteBufAllocator[index] = | ||
createByteBufAllocator( | ||
conf.networkMemoryAllocatorPooled(), true, allowCache, conf.networkAllocatorArenas()); | ||
if (source != null) { | ||
new NettyMemoryMetrics( | ||
_sharedPooledByteBufAllocator[index], | ||
_sharedByteBufAllocator[index], | ||
"shared-pool-" + index, | ||
conf.networkAllocatorVerboseMetric(), | ||
source, | ||
Collections.emptyMap()); | ||
} | ||
} | ||
return _sharedPooledByteBufAllocator[index]; | ||
return _sharedByteBufAllocator[index]; | ||
} | ||
|
||
public static PooledByteBufAllocator getPooledByteBufAllocator( | ||
public static ByteBufAllocator getByteBufAllocator( | ||
TransportConf conf, AbstractSource source, boolean allowCache) { | ||
return getPooledByteBufAllocator(conf, source, allowCache, 0); | ||
return getByteBufAllocator(conf, source, allowCache, 0); | ||
} | ||
|
||
public static PooledByteBufAllocator getPooledByteBufAllocator( | ||
public static ByteBufAllocator getByteBufAllocator( | ||
TransportConf conf, AbstractSource source, boolean allowCache, int coreNum) { | ||
if (conf.getCelebornConf().networkShareMemoryAllocator()) { | ||
return getSharedPooledByteBufAllocator( | ||
return getSharedByteBufAllocator( | ||
conf.getCelebornConf(), | ||
source, | ||
allowCache && conf.getCelebornConf().networkMemoryAllocatorAllowCache()); | ||
|
@@ -160,8 +167,12 @@ public static PooledByteBufAllocator getPooledByteBufAllocator( | |
} else { | ||
arenas = conf.getCelebornConf().networkAllocatorArenas(); | ||
} | ||
PooledByteBufAllocator allocator = | ||
createPooledByteBufAllocator(conf.preferDirectBufs(), allowCache, arenas); | ||
ByteBufAllocator allocator = | ||
createByteBufAllocator( | ||
conf.getCelebornConf().networkMemoryAllocatorPooled(), | ||
conf.preferDirectBufs(), | ||
allowCache, | ||
arenas); | ||
if (source != null) { | ||
String poolName = "default-netty-pool"; | ||
Map<String, String> labels = new HashMap<>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnpooledByteBufAllocator only supports these two metrics