Search in sources :

Example 56 with NetworkBufferPool

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

the class DataBufferTest method createDataBuffer.

private DataBuffer createDataBuffer(int bufferPoolSize, int bufferSize, int numSubpartitions, int[] customReadOrder) throws IOException {
    NetworkBufferPool globalPool = new NetworkBufferPool(bufferPoolSize, bufferSize);
    BufferPool bufferPool = globalPool.createBufferPool(bufferPoolSize, bufferPoolSize);
    if (useHashBuffer) {
        return new HashBasedDataBuffer(bufferPool, numSubpartitions, bufferPoolSize, customReadOrder);
    } else {
        return new SortBasedDataBuffer(bufferPool, numSubpartitions, bufferSize, bufferPoolSize, customReadOrder);
    }
}
Also used : BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)

Example 57 with NetworkBufferPool

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

the class NettyMessageClientDecoderDelegateTest method setup.

@Before
public void setup() throws IOException, InterruptedException {
    CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
    networkBufferPool = new NetworkBufferPool(NUMBER_OF_BUFFER_RESPONSES, BUFFER_SIZE);
    channel = new EmbeddedChannel(new NettyMessageClientDecoderDelegate(handler));
    inputGate = createSingleInputGate(1, networkBufferPool);
    RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, new TestingPartitionRequestClient(), NUMBER_OF_BUFFER_RESPONSES);
    inputGate.setInputChannels(inputChannel);
    inputGate.setup();
    inputChannel.requestSubpartition();
    handler.addInputChannel(inputChannel);
    inputChannelId = inputChannel.getInputChannelId();
    SingleInputGate releasedInputGate = createSingleInputGate(1, networkBufferPool);
    RemoteInputChannel releasedInputChannel = new InputChannelBuilder().buildRemoteChannel(inputGate);
    releasedInputGate.close();
    handler.addInputChannel(releasedInputChannel);
    releasedInputChannelId = releasedInputChannel.getInputChannelId();
}
Also used : InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) TestingPartitionRequestClient(org.apache.flink.runtime.io.network.TestingPartitionRequestClient) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) Before(org.junit.Before)

Example 58 with NetworkBufferPool

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

the class NettyPartitionRequestClientTest method testResumeConsumption.

@Test
public void testResumeConsumption() throws Exception {
    final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
    final EmbeddedChannel channel = new EmbeddedChannel(handler);
    final PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
    final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
    final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
    final RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
    try {
        final BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
        inputGate.setBufferPool(bufferPool);
        inputGate.setupChannels();
        inputChannel.requestSubpartition();
        inputChannel.resumeConsumption();
        channel.runPendingTasks();
        Object readFromOutbound = channel.readOutbound();
        assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
        readFromOutbound = channel.readOutbound();
        assertThat(readFromOutbound, instanceOf(ResumeConsumption.class));
        assertEquals(inputChannel.getInputChannelId(), ((ResumeConsumption) readFromOutbound).receiverId);
        assertNull(channel.readOutbound());
    } finally {
        // Release all the buffer resources
        inputGate.close();
        networkBufferPool.destroyAllBufferPools();
        networkBufferPool.destroy();
    }
}
Also used : ResumeConsumption(org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) PartitionRequestClient(org.apache.flink.runtime.io.network.PartitionRequestClient) InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.mockConnectionManagerWithPartitionRequestClient) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) Test(org.junit.Test)

Example 59 with NetworkBufferPool

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

the class NettyPartitionRequestClientTest method testPartitionRequestClientReuse.

@Test
public void testPartitionRequestClientReuse() throws Exception {
    final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
    final EmbeddedChannel channel = new EmbeddedChannel(handler);
    final NettyPartitionRequestClient client = createPartitionRequestClient(channel, handler, true);
    final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
    final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
    final RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
    try {
        // Client should not be disposed in idle
        client.close(inputChannel);
        assertFalse(client.canBeDisposed());
        // Client should be disposed in error
        handler.notifyAllChannelsOfErrorAndClose(new RuntimeException());
        assertTrue(client.canBeDisposed());
    } finally {
        // Release all the buffer resources
        inputGate.close();
        networkBufferPool.destroyAllBufferPools();
        networkBufferPool.destroy();
    }
}
Also used : EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) Test(org.junit.Test)

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