Class NetworkBufferPool
java.lang.Object
org.apache.flink.runtime.io.network.buffer.NetworkBufferPool
- All Implemented Interfaces:
org.apache.flink.core.memory.MemorySegmentProvider,AvailabilityProvider,BufferPoolFactory
public class NetworkBufferPool
extends Object
implements BufferPoolFactory, org.apache.flink.core.memory.MemorySegmentProvider, AvailabilityProvider
The NetworkBufferPool is a fixed size pool of
MemorySegment instances for the network
stack.
The NetworkBufferPool creates LocalBufferPools from which the individual tasks draw
the buffers for the network data transfer. When new local buffer pools are created, the
NetworkBufferPool dynamically redistributes the buffers between the pools.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AvailabilityProvider.AvailabilityHelper -
Field Summary
FieldsFields inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AVAILABLE -
Constructor Summary
ConstructorsConstructorDescriptionNetworkBufferPool(int numberOfSegmentsToAllocate, int segmentSize) NetworkBufferPool(int numberOfSegmentsToAllocate, int segmentSize, Duration requestSegmentsTimeout) Allocates allMemorySegmentinstances managed by this pool. -
Method Summary
Modifier and TypeMethodDescriptionintcreateBufferPool(int numRequiredBuffers, int maxUsedBuffers) Tries to create a buffer pool, which is guaranteed to provide at least the number of required buffers.createBufferPool(int numRequiredBuffers, int maxUsedBuffers, int numSubpartitions, int maxBuffersPerChannel, int maxOverdraftBuffersPerGate) Tries to create a buffer pool with an owner, which is guaranteed to provide at least the number of required buffers.voiddestroy()voidDestroys all buffer pools that allocate their buffers from this buffer pool (created viacreateBufferPool(int, int)).voiddestroyBufferPool(BufferPool bufferPool) Destroy callback for updating factory book keeping.Returns a future that is completed when there are free segments in this pool.longlonglongintintintintlongintlongbooleanvoidvoidrecyclePooledMemorySegment(org.apache.flink.core.memory.MemorySegment segment) Corresponding torequestPooledMemorySegmentsBlocking(int)andrequestPooledMemorySegment(), this method is for pooled memory segments recycling.voidrecycleUnpooledMemorySegments(Collection<org.apache.flink.core.memory.MemorySegment> segments) Corresponding torequestUnpooledMemorySegments(int), this method is for unpooled memory segments recycling.org.apache.flink.core.memory.MemorySegmentDifferent fromrequestUnpooledMemorySegments(int)for unpooled segments allocation.List<org.apache.flink.core.memory.MemorySegment>requestPooledMemorySegmentsBlocking(int numberOfSegmentsToRequest) List<org.apache.flink.core.memory.MemorySegment>requestUnpooledMemorySegments(int numberOfSegmentsToRequest) Unpooled memory segments are requested directly fromNetworkBufferPool, as opposed to pooled segments, that are requested throughBufferPoolthat was created from thisNetworkBufferPool(seecreateBufferPool(int, int)).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
isApproximatelyAvailable, isAvailable
-
Field Details
-
UNBOUNDED_POOL_SIZE
public static final int UNBOUNDED_POOL_SIZE- See Also:
-
-
Constructor Details
-
NetworkBufferPool
@VisibleForTesting public NetworkBufferPool(int numberOfSegmentsToAllocate, int segmentSize) -
NetworkBufferPool
public NetworkBufferPool(int numberOfSegmentsToAllocate, int segmentSize, Duration requestSegmentsTimeout) Allocates allMemorySegmentinstances managed by this pool.
-
-
Method Details
-
requestPooledMemorySegment
@Nullable public org.apache.flink.core.memory.MemorySegment requestPooledMemorySegment()Different fromrequestUnpooledMemorySegments(int)for unpooled segments allocation. This method and the belowrequestPooledMemorySegmentsBlocking(int)method are designed to be used fromLocalBufferPoolfor pooled memory segments allocation. Note that these methods for pooled memory segments requesting and recycling are prohibited from acquiring the factoryLock to avoid deadlock. -
requestPooledMemorySegmentsBlocking
public List<org.apache.flink.core.memory.MemorySegment> requestPooledMemorySegmentsBlocking(int numberOfSegmentsToRequest) throws IOException - Throws:
IOException
-
recyclePooledMemorySegment
public void recyclePooledMemorySegment(org.apache.flink.core.memory.MemorySegment segment) Corresponding torequestPooledMemorySegmentsBlocking(int)andrequestPooledMemorySegment(), this method is for pooled memory segments recycling. -
requestUnpooledMemorySegments
public List<org.apache.flink.core.memory.MemorySegment> requestUnpooledMemorySegments(int numberOfSegmentsToRequest) throws IOException Unpooled memory segments are requested directly fromNetworkBufferPool, as opposed to pooled segments, that are requested throughBufferPoolthat was created from thisNetworkBufferPool(seecreateBufferPool(int, int)). They are used for example for exclusiveRemoteInputChannelcredits, that are permanently assigned to that channel, and never returned to anyBufferPool. As opposed to pooled segments, when requested, unpooled segments needs to be accounted againstnumTotalRequiredBuffers, which might require redistribution of the segments.- Specified by:
requestUnpooledMemorySegmentsin interfaceorg.apache.flink.core.memory.MemorySegmentProvider- Throws:
IOException
-
recycleUnpooledMemorySegments
public void recycleUnpooledMemorySegments(Collection<org.apache.flink.core.memory.MemorySegment> segments) Corresponding torequestUnpooledMemorySegments(int), this method is for unpooled memory segments recycling.- Specified by:
recycleUnpooledMemorySegmentsin interfaceorg.apache.flink.core.memory.MemorySegmentProvider
-
destroy
public void destroy() -
isDestroyed
public boolean isDestroyed() -
getTotalNumberOfMemorySegments
public int getTotalNumberOfMemorySegments() -
getTotalMemory
public long getTotalMemory() -
getNumberOfAvailableMemorySegments
public int getNumberOfAvailableMemorySegments() -
getAvailableMemory
public long getAvailableMemory() -
getNumberOfUsedMemorySegments
public int getNumberOfUsedMemorySegments() -
getUsedMemory
public long getUsedMemory() -
getNumberOfRegisteredBufferPools
public int getNumberOfRegisteredBufferPools() -
getEstimatedNumberOfRequestedMemorySegments
public long getEstimatedNumberOfRequestedMemorySegments() -
getEstimatedRequestedMemory
public long getEstimatedRequestedMemory() -
getEstimatedRequestedSegmentsUsage
public int getEstimatedRequestedSegmentsUsage() -
maybeLogUsageWarning
public void maybeLogUsageWarning() -
countBuffers
public int countBuffers() -
getAvailableFuture
Returns a future that is completed when there are free segments in this pool.- Specified by:
getAvailableFuturein interfaceAvailabilityProvider- Returns:
- a future that is completed if the respective provider is available.
-
createBufferPool
Description copied from interface:BufferPoolFactoryTries to create a buffer pool, which is guaranteed to provide at least the number of required buffers.The buffer pool is of dynamic size with at least numRequiredBuffers buffers.
- Specified by:
createBufferPoolin interfaceBufferPoolFactory- Parameters:
numRequiredBuffers- minimum number of network buffers in this poolmaxUsedBuffers- maximum number of network buffers this pool offers- Throws:
IOException
-
createBufferPool
public BufferPool createBufferPool(int numRequiredBuffers, int maxUsedBuffers, int numSubpartitions, int maxBuffersPerChannel, int maxOverdraftBuffersPerGate) throws IOException Description copied from interface:BufferPoolFactoryTries to create a buffer pool with an owner, which is guaranteed to provide at least the number of required buffers.The buffer pool is of dynamic size with at least numRequiredBuffers buffers.
- Specified by:
createBufferPoolin interfaceBufferPoolFactory- Parameters:
numRequiredBuffers- minimum number of network buffers in this poolmaxUsedBuffers- maximum number of network buffers this pool offersnumSubpartitions- number of subpartitions in this poolmaxBuffersPerChannel- maximum number of buffers to use for each channelmaxOverdraftBuffersPerGate- maximum number of overdraft buffers to use for each gate- Throws:
IOException
-
destroyBufferPool
Description copied from interface:BufferPoolFactoryDestroy callback for updating factory book keeping.- Specified by:
destroyBufferPoolin interfaceBufferPoolFactory
-
destroyAllBufferPools
public void destroyAllBufferPools()Destroys all buffer pools that allocate their buffers from this buffer pool (created viacreateBufferPool(int, int)).
-