Search in sources :

Example 6 with BufferConsumer

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

the class BufferWritingResultPartition method createBroadcastBufferConsumers.

private void createBroadcastBufferConsumers(BufferBuilder buffer, int partialRecordBytes, int minDesirableBufferSize) throws IOException {
    try (final BufferConsumer consumer = buffer.createBufferConsumerFromBeginning()) {
        int desirableBufferSize = Integer.MAX_VALUE;
        for (ResultSubpartition subpartition : subpartitions) {
            int subPartitionBufferSize = subpartition.add(consumer.copy(), partialRecordBytes);
            desirableBufferSize = subPartitionBufferSize > 0 ? Math.min(desirableBufferSize, subPartitionBufferSize) : desirableBufferSize;
        }
        resizeBuffer(buffer, desirableBufferSize, minDesirableBufferSize);
    }
}
Also used : BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer)

Example 7 with BufferConsumer

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

the class BufferWritingResultPartition method broadcastEvent.

@Override
public void broadcastEvent(AbstractEvent event, boolean isPriorityEvent) throws IOException {
    checkInProduceState();
    finishBroadcastBufferBuilder();
    finishUnicastBufferBuilders();
    try (BufferConsumer eventBufferConsumer = EventSerializer.toBufferConsumer(event, isPriorityEvent)) {
        totalWrittenBytes += ((long) eventBufferConsumer.getWrittenBytes() * numSubpartitions);
        for (ResultSubpartition subpartition : subpartitions) {
            // Retain the buffer so that it can be recycled by each channel of targetPartition
            subpartition.add(eventBufferConsumer.copy(), 0);
        }
    }
}
Also used : BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer)

Example 8 with BufferConsumer

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

the class InputGateFairnessTest method testFairConsumptionLocalChannelsPreFilled.

@Test
public void testFairConsumptionLocalChannelsPreFilled() throws Exception {
    final int numberOfChannels = 37;
    final int buffersPerChannel = 27;
    PipelinedResultPartition[] resultPartitions = IntStream.range(0, numberOfChannels).mapToObj(i -> (PipelinedResultPartition) new ResultPartitionBuilder().build()).toArray(PipelinedResultPartition[]::new);
    final BufferConsumer bufferConsumer = createFilledFinishedBufferConsumer(42);
    // ----- create some source channels and fill them with buffers -----
    final PipelinedSubpartition[] sources = Arrays.stream(resultPartitions).map(resultPartition -> resultPartition.getAllPartitions()[0]).toArray(PipelinedSubpartition[]::new);
    for (final PipelinedSubpartition subpartition : sources) {
        for (int p = 0; p < buffersPerChannel; p++) {
            subpartition.add(bufferConsumer.copy());
        }
        subpartition.finish();
    }
    for (ResultPartition rp : resultPartitions) {
        rp.setup();
    }
    // ----- create reading side -----
    final SingleInputGate gate = createFairnessVerifyingInputGate(numberOfChannels);
    final InputChannel[] inputChannels = IntStream.range(0, numberOfChannels).mapToObj(i -> InputChannelBuilder.newBuilder().setChannelIndex(i).setPartitionManager(resultPartitions[i].partitionManager).setPartitionId(resultPartitions[i].getPartitionId()).buildLocalChannel(gate)).toArray(InputChannel[]::new);
    setupInputGate(gate, inputChannels);
    // read all the buffers and the EOF event
    for (int i = numberOfChannels * (buffersPerChannel + 1); i > 0; --i) {
        assertNotNull(gate.getNext());
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (PipelinedSubpartition source : sources) {
            int size = source.getNumberOfQueuedBuffers();
            min = Math.min(min, size);
            max = Math.max(max, size);
        }
        assertTrue(max == min || max == (min + 1));
    }
    assertFalse(gate.getNext().isPresent());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TestBufferFactory(org.apache.flink.runtime.io.network.util.TestBufferFactory) SystemClock(org.apache.flink.util.clock.SystemClock) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) SubpartitionIndexRange(org.apache.flink.runtime.deployment.SubpartitionIndexRange) InputChannelTestUtils.createDummyConnectionManager(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createDummyConnectionManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) Assert.fail(org.junit.Assert.fail) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) EventSerializer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) Collection(java.util.Collection) InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) BufferBuilderTestUtils.createFilledFinishedBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) NoOpBufferPool(org.apache.flink.runtime.io.network.buffer.NoOpBufferPool) UnpooledMemorySegmentProvider(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.UnpooledMemorySegmentProvider) Collections(java.util.Collections) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) SupplierWithException(org.apache.flink.util.function.SupplierWithException) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) BufferBuilderTestUtils.createFilledFinishedBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 9 with BufferConsumer

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

the class StreamTaskNetworkInputTest method createDataBuffer.

private BufferOrEvent createDataBuffer() throws IOException {
    try (BufferBuilder bufferBuilder = BufferBuilderTestUtils.createEmptyBufferBuilder(PAGE_SIZE)) {
        BufferConsumer bufferConsumer = bufferBuilder.createBufferConsumer();
        serializeRecord(42L, bufferBuilder);
        serializeRecord(44L, bufferBuilder);
        return new BufferOrEvent(bufferConsumer.build(), new InputChannelInfo(0, 0));
    }
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) BufferBuilder(org.apache.flink.runtime.io.network.buffer.BufferBuilder) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)

Example 10 with BufferConsumer

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

the class SubpartitionTestBase method testAddAfterFinish.

@Test
public void testAddAfterFinish() throws Exception {
    final ResultSubpartition subpartition = createSubpartition();
    try {
        subpartition.finish();
        assertEquals(1, subpartition.getTotalNumberOfBuffersUnsafe());
        assertEquals(0, subpartition.getBuffersInBacklogUnsafe());
        BufferConsumer bufferConsumer = createFilledFinishedBufferConsumer(4096);
        assertEquals(-1, subpartition.add(bufferConsumer));
        assertTrue(bufferConsumer.isRecycled());
        assertEquals(1, subpartition.getTotalNumberOfBuffersUnsafe());
        assertEquals(0, subpartition.getBuffersInBacklogUnsafe());
    } finally {
        if (subpartition != null) {
            subpartition.release();
        }
    }
}
Also used : BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) BufferBuilderTestUtils.createFilledFinishedBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer) Test(org.junit.Test)

Aggregations

BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)33 BufferBuilderTestUtils.createFilledFinishedBufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer)11 Test (org.junit.Test)11 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)9 BufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilder)9 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)6 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)5 IOException (java.io.IOException)4 MemorySegment (org.apache.flink.core.memory.MemorySegment)4 AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)3 EndOfPartitionEvent (org.apache.flink.runtime.io.network.api.EndOfPartitionEvent)3 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2