Search in sources :

Example 1 with BufferDecompressor

use of org.apache.flink.runtime.io.network.buffer.BufferDecompressor 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 2 with BufferDecompressor

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

the class SingleInputGateTest method testGetCompressedBuffer.

/**
 * Tests that the compressed buffer will be decompressed after calling {@link
 * SingleInputGate#getNext()}.
 */
@Test
public void testGetCompressedBuffer() throws Exception {
    int bufferSize = 1024;
    String compressionCodec = "LZ4";
    BufferCompressor compressor = new BufferCompressor(bufferSize, compressionCodec);
    BufferDecompressor decompressor = new BufferDecompressor(bufferSize, compressionCodec);
    try (SingleInputGate inputGate = new SingleInputGateBuilder().setBufferDecompressor(decompressor).build()) {
        TestInputChannel inputChannel = new TestInputChannel(inputGate, 0);
        MemorySegment segment = MemorySegmentFactory.allocateUnpooledSegment(bufferSize);
        for (int i = 0; i < bufferSize; i += 8) {
            segment.putLongLittleEndian(i, i);
        }
        Buffer uncompressedBuffer = new NetworkBuffer(segment, FreeingBufferRecycler.INSTANCE);
        uncompressedBuffer.setSize(bufferSize);
        Buffer compressedBuffer = compressor.compressToOriginalBuffer(uncompressedBuffer);
        assertTrue(compressedBuffer.isCompressed());
        inputChannel.read(compressedBuffer);
        inputGate.setInputChannels(inputChannel);
        inputGate.notifyChannelNonEmpty(inputChannel);
        Optional<BufferOrEvent> bufferOrEvent = inputGate.getNext();
        assertTrue(bufferOrEvent.isPresent());
        assertTrue(bufferOrEvent.get().isBuffer());
        ByteBuffer buffer = bufferOrEvent.get().getBuffer().getNioBufferReadable().order(ByteOrder.LITTLE_ENDIAN);
        for (int i = 0; i < bufferSize; i += 8) {
            assertEquals(i, buffer.getLong());
        }
    }
}
Also used : NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) ByteBuffer(java.nio.ByteBuffer) TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferDecompressor(org.apache.flink.runtime.io.network.buffer.BufferDecompressor) MemorySegment(org.apache.flink.core.memory.MemorySegment) BufferCompressor(org.apache.flink.runtime.io.network.buffer.BufferCompressor) NetworkBuffer(org.apache.flink.runtime.io.network.buffer.NetworkBuffer) Test(org.junit.Test)

Example 3 with BufferDecompressor

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

the class CreditBasedPartitionRequestClientHandlerTest method testReceiveCompressedBuffer.

/**
 * Verifies that {@link BufferResponse} of compressed {@link Buffer} can be handled correctly.
 */
@Test
public void testReceiveCompressedBuffer() throws Exception {
    int bufferSize = 1024;
    String compressionCodec = "LZ4";
    BufferCompressor compressor = new BufferCompressor(bufferSize, compressionCodec);
    BufferDecompressor decompressor = new BufferDecompressor(bufferSize, compressionCodec);
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, bufferSize);
    SingleInputGate inputGate = new SingleInputGateBuilder().setBufferDecompressor(decompressor).setSegmentProvider(networkBufferPool).build();
    RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, null);
    inputGate.setInputChannels(inputChannel);
    try {
        BufferPool bufferPool = networkBufferPool.createBufferPool(8, 8);
        inputGate.setBufferPool(bufferPool);
        inputGate.setupChannels();
        CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
        handler.addInputChannel(inputChannel);
        Buffer buffer = compressor.compressToOriginalBuffer(TestBufferFactory.createBuffer(bufferSize));
        BufferResponse bufferResponse = createBufferResponse(buffer, 0, inputChannel.getInputChannelId(), 2, new NetworkBufferAllocator(handler));
        assertTrue(bufferResponse.isCompressed);
        handler.channelRead(null, bufferResponse);
        Buffer receivedBuffer = inputChannel.getNextReceivedBuffer();
        assertNotNull(receivedBuffer);
        assertTrue(receivedBuffer.isCompressed());
        receivedBuffer.recycleBuffer();
    } finally {
        releaseResource(inputGate, networkBufferPool);
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) BufferDecompressor(org.apache.flink.runtime.io.network.buffer.BufferDecompressor) 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) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) BufferCompressor(org.apache.flink.runtime.io.network.buffer.BufferCompressor) BufferResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse) Test(org.junit.Test)

Aggregations

BufferDecompressor (org.apache.flink.runtime.io.network.buffer.BufferDecompressor)3 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)2 BufferCompressor (org.apache.flink.runtime.io.network.buffer.BufferCompressor)2 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)2 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 SubpartitionIndexRange (org.apache.flink.runtime.deployment.SubpartitionIndexRange)1 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)1 InputChannelMetrics (org.apache.flink.runtime.io.network.metrics.InputChannelMetrics)1 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)1 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)1 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)1 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)1 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)1 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)1 TestBufferFactory.createBuffer (org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer)1