Search in sources :

Example 6 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class ResultSubpartitionRecoveredStateHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    // given: Segment provider with defined number of allocated segments.
    channelInfo = new ResultSubpartitionInfo(0, 0);
    networkBufferPool = new NetworkBufferPool(preAllocatedSegments, 1024);
    partition = new ResultPartitionBuilder().setNetworkBufferPool(networkBufferPool).build();
    partition.setup();
    rstHandler = buildResultStateHandler(partition);
}
Also used : ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) Before(org.junit.Before)

Example 7 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class SequentialChannelStateReaderImplTest method withInputGates.

private void withInputGates(ThrowingConsumer<InputGate[], Exception> action) throws Exception {
    SingleInputGate[] gates = new SingleInputGate[parLevel];
    final int segmentsToAllocate = parLevel + parLevel * parLevel * buffersPerChannel;
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(segmentsToAllocate, bufferSize);
    try (Closer poolCloser = Closer.create()) {
        poolCloser.register(networkBufferPool::destroy);
        poolCloser.register(networkBufferPool::destroyAllBufferPools);
        try (Closer gateCloser = Closer.create()) {
            for (int i = 0; i < parLevel; i++) {
                gates[i] = new SingleInputGateBuilder().setNumberOfChannels(parLevel).setSingleInputGateIndex(i).setBufferPoolFactory(networkBufferPool.createBufferPool(1, buffersPerChannel)).setSegmentProvider(networkBufferPool).setChannelFactory((builder, gate) -> builder.setNetworkBuffersPerChannel(buffersPerChannel).buildRemoteRecoveredChannel(gate)).build();
                gates[i].setup();
                gateCloser.register(gates[i]::close);
            }
            action.accept(gates);
        }
        assertEquals(segmentsToAllocate, networkBufferPool.getNumberOfAvailableMemorySegments());
    }
}
Also used : Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)

Example 8 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class SequentialChannelStateReaderImplTest method withResultPartitions.

private void withResultPartitions(ThrowingConsumer<BufferWritingResultPartition[], Exception> action) throws Exception {
    int segmentsToAllocate = parLevel * parLevel * buffersPerChannel;
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(segmentsToAllocate, bufferSize);
    BufferWritingResultPartition[] resultPartitions = range(0, parLevel).mapToObj(i -> new ResultPartitionBuilder().setResultPartitionIndex(i).setNumberOfSubpartitions(parLevel).setNetworkBufferPool(networkBufferPool).build()).toArray(BufferWritingResultPartition[]::new);
    try {
        for (ResultPartition resultPartition : resultPartitions) {
            resultPartition.setup();
        }
        action.accept(resultPartitions);
    } finally {
        for (ResultPartition resultPartition : resultPartitions) {
            resultPartition.close();
        }
        try {
            assertEquals(segmentsToAllocate, networkBufferPool.getNumberOfAvailableMemorySegments());
        } finally {
            networkBufferPool.destroyAllBufferPools();
            networkBufferPool.destroy();
        }
    }
}
Also used : BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Tuple2(org.apache.flink.api.java.tuple.Tuple2) IntStream.range(java.util.stream.IntStream.range) BiFunction(java.util.function.BiFunction) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Random(java.util.Random) Function(java.util.function.Function) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ArrayList(java.util.ArrayList) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) DataOutputStream(java.io.DataOutputStream) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) Parameterized(org.junit.runners.Parameterized) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) MemorySegmentFactory(org.apache.flink.core.memory.MemorySegmentFactory) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle) Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) Assert.assertTrue(org.junit.Assert.assertTrue) FreeingBufferRecycler(org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler) Test(org.junit.Test) IOException(java.io.IOException) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) ResultSubpartitionStateHandle(org.apache.flink.runtime.state.ResultSubpartitionStateHandle) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) Function.identity(java.util.function.Function.identity) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Optional(java.util.Optional) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Collections(java.util.Collections) StateObjectCollection(org.apache.flink.runtime.checkpoint.StateObjectCollection) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Assert.assertEquals(org.junit.Assert.assertEquals) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition)

Example 9 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class SingleInputGateFactory method create.

/**
 * Creates an input gate and all of its input channels.
 */
public SingleInputGate create(@Nonnull ShuffleIOOwnerContext owner, int gateIndex, @Nonnull InputGateDeploymentDescriptor igdd, @Nonnull PartitionProducerStateProvider partitionProducerStateProvider) {
    SupplierWithException<BufferPool, IOException> bufferPoolFactory = createBufferPoolFactory(networkBufferPool, floatingNetworkBuffersPerGate);
    BufferDecompressor bufferDecompressor = null;
    if (igdd.getConsumedPartitionType().isBlocking() && blockingShuffleCompressionEnabled) {
        bufferDecompressor = new BufferDecompressor(networkBufferSize, compressionCodec);
    }
    final String owningTaskName = owner.getOwnerName();
    final MetricGroup networkInputGroup = owner.getInputGroup();
    SubpartitionIndexRange subpartitionIndexRange = igdd.getConsumedSubpartitionIndexRange();
    SingleInputGate inputGate = new SingleInputGate(owningTaskName, gateIndex, igdd.getConsumedResultId(), igdd.getConsumedPartitionType(), subpartitionIndexRange, calculateNumChannels(igdd.getShuffleDescriptors().length, subpartitionIndexRange), partitionProducerStateProvider, bufferPoolFactory, bufferDecompressor, networkBufferPool, networkBufferSize, new ThroughputCalculator(SystemClock.getInstance()), maybeCreateBufferDebloater(gateIndex, networkInputGroup.addGroup(gateIndex)));
    InputChannelMetrics metrics = new InputChannelMetrics(networkInputGroup, owner.getParentGroup());
    createInputChannels(owningTaskName, igdd, inputGate, subpartitionIndexRange, metrics);
    return inputGate;
}
Also used : NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) MetricGroup(org.apache.flink.metrics.MetricGroup) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) IOException(java.io.IOException) InputChannelMetrics(org.apache.flink.runtime.io.network.metrics.InputChannelMetrics) SubpartitionIndexRange(org.apache.flink.runtime.deployment.SubpartitionIndexRange) BufferDecompressor(org.apache.flink.runtime.io.network.buffer.BufferDecompressor)

Example 10 with NetworkBufferPool

use of org.apache.flink.runtime.io.network.buffer.NetworkBufferPool in project flink by apache.

the class NettyShuffleServiceFactory method createNettyShuffleEnvironment.

@VisibleForTesting
static NettyShuffleEnvironment createNettyShuffleEnvironment(NettyShuffleEnvironmentConfiguration config, ResourceID taskExecutorResourceId, TaskEventPublisher taskEventPublisher, ResultPartitionManager resultPartitionManager, MetricGroup metricGroup, Executor ioExecutor) {
    checkNotNull(config);
    checkNotNull(taskExecutorResourceId);
    checkNotNull(taskEventPublisher);
    checkNotNull(resultPartitionManager);
    checkNotNull(metricGroup);
    NettyConfig nettyConfig = config.nettyConfig();
    FileChannelManager fileChannelManager = new FileChannelManagerImpl(config.getTempDirs(), DIR_NAME_PREFIX);
    if (LOG.isInfoEnabled()) {
        LOG.info("Created a new {} for storing result partitions of BLOCKING shuffles. Used directories:\n\t{}", FileChannelManager.class.getSimpleName(), Arrays.stream(fileChannelManager.getPaths()).map(File::getAbsolutePath).collect(Collectors.joining("\n\t")));
    }
    ConnectionManager connectionManager = nettyConfig != null ? new NettyConnectionManager(resultPartitionManager, taskEventPublisher, nettyConfig, config.getMaxNumberOfConnections(), config.isConnectionReuseEnabled()) : new LocalConnectionManager();
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(config.numNetworkBuffers(), config.networkBufferSize(), config.getRequestSegmentsTimeout());
    // we create a separated buffer pool here for batch shuffle instead of reusing the network
    // buffer pool directly to avoid potential side effects of memory contention, for example,
    // dead lock or "insufficient network buffer" error
    BatchShuffleReadBufferPool batchShuffleReadBufferPool = new BatchShuffleReadBufferPool(config.batchShuffleReadMemoryBytes(), config.networkBufferSize());
    // we create a separated IO executor pool here for batch shuffle instead of reusing the
    // TaskManager IO executor pool directly to avoid the potential side effects of execution
    // contention, for example, too long IO or waiting time leading to starvation or timeout
    ExecutorService batchShuffleReadIOExecutor = Executors.newFixedThreadPool(Math.max(1, Math.min(batchShuffleReadBufferPool.getMaxConcurrentRequests(), 4 * Hardware.getNumberCPUCores())), new ExecutorThreadFactory("blocking-shuffle-io"));
    registerShuffleMetrics(metricGroup, networkBufferPool);
    ResultPartitionFactory resultPartitionFactory = new ResultPartitionFactory(resultPartitionManager, fileChannelManager, networkBufferPool, batchShuffleReadBufferPool, batchShuffleReadIOExecutor, config.getBlockingSubpartitionType(), config.networkBuffersPerChannel(), config.floatingNetworkBuffersPerGate(), config.networkBufferSize(), config.isBlockingShuffleCompressionEnabled(), config.getCompressionCodec(), config.getMaxBuffersPerChannel(), config.sortShuffleMinBuffers(), config.sortShuffleMinParallelism(), config.isSSLEnabled());
    SingleInputGateFactory singleInputGateFactory = new SingleInputGateFactory(taskExecutorResourceId, config, connectionManager, resultPartitionManager, taskEventPublisher, networkBufferPool);
    return new NettyShuffleEnvironment(taskExecutorResourceId, config, networkBufferPool, connectionManager, resultPartitionManager, fileChannelManager, resultPartitionFactory, singleInputGateFactory, ioExecutor, batchShuffleReadBufferPool, batchShuffleReadIOExecutor);
}
Also used : BatchShuffleReadBufferPool(org.apache.flink.runtime.io.disk.BatchShuffleReadBufferPool) NettyConfig(org.apache.flink.runtime.io.network.netty.NettyConfig) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) FileChannelManager(org.apache.flink.runtime.io.disk.FileChannelManager) FileChannelManagerImpl(org.apache.flink.runtime.io.disk.FileChannelManagerImpl) NettyConnectionManager(org.apache.flink.runtime.io.network.netty.NettyConnectionManager) ResultPartitionFactory(org.apache.flink.runtime.io.network.partition.ResultPartitionFactory) ExecutorService(java.util.concurrent.ExecutorService) SingleInputGateFactory(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateFactory) NettyConnectionManager(org.apache.flink.runtime.io.network.netty.NettyConnectionManager) File(java.io.File) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)59 Test (org.junit.Test)39 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)30 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)26 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)21 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)17 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)17 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)14 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)11 IOException (java.io.IOException)10 PartitionRequestClient (org.apache.flink.runtime.io.network.PartitionRequestClient)9 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)8 NoOpBufferPool (org.apache.flink.runtime.io.network.buffer.NoOpBufferPool)8 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)8 ExecutorService (java.util.concurrent.ExecutorService)7 Before (org.junit.Before)7 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)6 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)6 EventSerializer.toBuffer (org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer)5 BufferBuilderTestUtils.buildSingleBuffer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSingleBuffer)5