Search in sources :

Example 6 with NettyShuffleEnvironment

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

the class PartitionRequestQueueTest method createFinishedPartitionWithFilledData.

private static ResultPartition createFinishedPartitionWithFilledData(ResultPartitionManager partitionManager) throws Exception {
    NettyShuffleEnvironment environment = new NettyShuffleEnvironmentBuilder().setResultPartitionManager(partitionManager).build();
    ResultPartition partition = createPartition(environment, fileChannelManager, ResultPartitionType.BLOCKING, 1);
    partition.setup();
    partition.emitRecord(ByteBuffer.allocate(BUFFER_SIZE), 0);
    partition.finish();
    return partition;
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition)

Example 7 with NettyShuffleEnvironment

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

the class InputBuffersMetricsTest method testCalculateTotalBuffersSize.

@Test
public void testCalculateTotalBuffersSize() throws Exception {
    int numberOfRemoteChannels = 2;
    int numberOfLocalChannels = 0;
    int numberOfBufferPerChannel = 2;
    int numberOfBuffersPerGate = 8;
    NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNetworkBuffersPerChannel(numberOfBufferPerChannel).setFloatingNetworkBuffersPerGate(numberOfBuffersPerGate).build();
    closeableRegistry.registerCloseable(network::close);
    SingleInputGate inputGate1 = buildInputGate(network, numberOfRemoteChannels, numberOfLocalChannels).f0;
    closeableRegistry.registerCloseable(inputGate1::close);
    inputGate1.setup();
    SingleInputGate[] inputGates = new SingleInputGate[] { inputGate1 };
    FloatingBuffersUsageGauge floatingBuffersUsageGauge = new FloatingBuffersUsageGauge(inputGates);
    ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new ExclusiveBuffersUsageGauge(inputGates);
    CreditBasedInputBuffersUsageGauge inputBufferPoolUsageGauge = new CreditBasedInputBuffersUsageGauge(floatingBuffersUsageGauge, exclusiveBuffersUsageGauge, inputGates);
    closeableRegistry.registerCloseable(network::close);
    closeableRegistry.registerCloseable(inputGate1::close);
    assertEquals(numberOfBuffersPerGate, floatingBuffersUsageGauge.calculateTotalBuffers(inputGate1));
    assertEquals(numberOfRemoteChannels * numberOfBufferPerChannel, exclusiveBuffersUsageGauge.calculateTotalBuffers(inputGate1));
    assertEquals(numberOfRemoteChannels * numberOfBufferPerChannel + numberOfBuffersPerGate, inputBufferPoolUsageGauge.calculateTotalBuffers(inputGate1));
}
Also used : ExclusiveBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge) FloatingBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) CreditBasedInputBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge) Test(org.junit.Test)

Example 8 with NettyShuffleEnvironment

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

the class InputBuffersMetricsTest method testExclusiveBuffersUsage.

@Test
public void testExclusiveBuffersUsage() throws Exception {
    int numberOfRemoteChannelsGate1 = 2;
    int numberOfLocalChannelsGate1 = 0;
    int numberOfRemoteChannelsGate2 = 1;
    int numberOfLocalChannelsGate2 = 1;
    int totalNumberOfRemoteChannels = numberOfRemoteChannelsGate1 + numberOfRemoteChannelsGate2;
    int buffersPerChannel = 2;
    int extraNetworkBuffersPerGate = 8;
    NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNetworkBuffersPerChannel(buffersPerChannel).setFloatingNetworkBuffersPerGate(extraNetworkBuffersPerGate).build();
    closeableRegistry.registerCloseable(network::close);
    Tuple2<SingleInputGate, List<RemoteInputChannel>> tuple1 = buildInputGate(network, numberOfRemoteChannelsGate1, numberOfLocalChannelsGate1);
    Tuple2<SingleInputGate, List<RemoteInputChannel>> tuple2 = buildInputGate(network, numberOfRemoteChannelsGate2, numberOfLocalChannelsGate2);
    SingleInputGate inputGate1 = tuple1.f0;
    SingleInputGate inputGate2 = tuple2.f0;
    closeableRegistry.registerCloseable(inputGate1::close);
    closeableRegistry.registerCloseable(inputGate2::close);
    inputGate1.setup();
    inputGate2.setup();
    List<RemoteInputChannel> remoteInputChannels = tuple1.f1;
    SingleInputGate[] inputGates = new SingleInputGate[] { tuple1.f0, tuple2.f0 };
    FloatingBuffersUsageGauge floatingBuffersUsageGauge = new FloatingBuffersUsageGauge(inputGates);
    ExclusiveBuffersUsageGauge exclusiveBuffersUsageGauge = new ExclusiveBuffersUsageGauge(inputGates);
    CreditBasedInputBuffersUsageGauge inputBuffersUsageGauge = new CreditBasedInputBuffersUsageGauge(floatingBuffersUsageGauge, exclusiveBuffersUsageGauge, inputGates);
    assertEquals(0.0, exclusiveBuffersUsageGauge.getValue(), 0.0);
    assertEquals(0.0, inputBuffersUsageGauge.getValue(), 0.0);
    int totalBuffers = extraNetworkBuffersPerGate * inputGates.length + buffersPerChannel * totalNumberOfRemoteChannels;
    int channelIndex = 1;
    for (RemoteInputChannel channel : remoteInputChannels) {
        drainAndValidate(buffersPerChannel, buffersPerChannel * channelIndex++, channel, totalBuffers, buffersPerChannel * totalNumberOfRemoteChannels, exclusiveBuffersUsageGauge, inputBuffersUsageGauge, inputGate1);
    }
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) CreditBasedInputBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.CreditBasedInputBuffersUsageGauge) ExclusiveBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.ExclusiveBuffersUsageGauge) FloatingBuffersUsageGauge(org.apache.flink.runtime.io.network.metrics.FloatingBuffersUsageGauge) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with NettyShuffleEnvironment

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

the class ResultPartitionTest method createResultPartition.

private BufferWritingResultPartition createResultPartition(ResultPartitionType partitionType) throws IOException {
    NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNumNetworkBuffers(10).setBufferSize(bufferSize).build();
    ResultPartition resultPartition = createPartition(network, fileChannelManager, partitionType, 2);
    resultPartition.setup();
    return (BufferWritingResultPartition) resultPartition;
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment)

Example 10 with NettyShuffleEnvironment

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

the class ResultPartitionTest method testReleaseMemoryOnPipelinedPartition.

/**
 * Tests {@link ResultPartition#close()} and {@link ResultPartition#release()} on a working
 * pipelined partition.
 */
@Test
public void testReleaseMemoryOnPipelinedPartition() throws Exception {
    final int numAllBuffers = 10;
    final NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNumNetworkBuffers(numAllBuffers).setBufferSize(bufferSize).build();
    final ResultPartition resultPartition = createPartition(network, ResultPartitionType.PIPELINED, 1);
    try {
        resultPartition.setup();
        // take all buffers (more than the minimum required)
        for (int i = 0; i < numAllBuffers; ++i) {
            resultPartition.emitRecord(ByteBuffer.allocate(bufferSize - 1), 0);
        }
        assertEquals(0, resultPartition.getBufferPool().getNumberOfAvailableMemorySegments());
        resultPartition.close();
        assertTrue(resultPartition.getBufferPool().isDestroyed());
        assertEquals(numAllBuffers, network.getNetworkBufferPool().getNumberOfUsedMemorySegments());
        resultPartition.release();
        assertEquals(0, network.getNetworkBufferPool().getNumberOfUsedMemorySegments());
    } finally {
        network.close();
    }
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) Test(org.junit.Test)

Aggregations

NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)33 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)26 Test (org.junit.Test)24 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)9 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)9 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)8 TestingConnectionManager (org.apache.flink.runtime.io.network.TestingConnectionManager)7 Task (org.apache.flink.runtime.taskmanager.Task)7 Configuration (org.apache.flink.configuration.Configuration)6 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)6 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)6 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)6 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 IOException (java.io.IOException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3