Search in sources :

Example 1 with SerializedUpdateBuffer

use of org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer in project flink by apache.

the class IterationHeadTask method initBackChannel.

/**
 * The iteration head prepares the backchannel: it allocates memory, instantiates a {@link
 * BlockingBackChannel} and hands it to the iteration tail via a {@link Broker} singleton.
 */
private BlockingBackChannel initBackChannel() throws Exception {
    /* get the size of the memory available to the backchannel */
    int backChannelMemoryPages = getMemoryManager().computeNumberOfPages(this.config.getRelativeBackChannelMemory());
    /* allocate the memory available to the backchannel */
    List<MemorySegment> segments = new ArrayList<MemorySegment>();
    int segmentSize = getMemoryManager().getPageSize();
    getMemoryManager().allocatePages(this, segments, backChannelMemoryPages);
    /* instantiate the backchannel */
    BlockingBackChannel backChannel = new BlockingBackChannel(new SerializedUpdateBuffer(segments, segmentSize, getIOManager()));
    /* hand the backchannel over to the iteration tail */
    Broker<BlockingBackChannel> broker = BlockingBackChannelBroker.instance();
    broker.handIn(brokerKey(), backChannel);
    return backChannel;
}
Also used : ArrayList(java.util.ArrayList) BlockingBackChannel(org.apache.flink.runtime.iterative.concurrent.BlockingBackChannel) MemorySegment(org.apache.flink.core.memory.MemorySegment) SerializedUpdateBuffer(org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer)

Example 2 with SerializedUpdateBuffer

use of org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer in project flink by apache.

the class BlockingBackChannelTest method multiThreaded.

@Test
public void multiThreaded() throws InterruptedException {
    BlockingQueue<Integer> dataChannel = new ArrayBlockingQueue<Integer>(1);
    List<String> actionLog = new ArrayList<>();
    SerializedUpdateBuffer buffer = Mockito.mock(SerializedUpdateBuffer.class);
    BlockingBackChannel channel = new BlockingBackChannel(buffer);
    Thread head = new Thread(new IterationHead(channel, dataChannel, actionLog));
    Thread tail = new Thread(new IterationTail(channel, dataChannel, actionLog));
    tail.start();
    head.start();
    head.join();
    tail.join();
    // int action = 0;
    // for (String log : actionLog) {
    // System.out.println("ACTION " + (++action) + ": " + log);
    // }
    assertEquals(12, actionLog.size());
    assertEquals("head sends data", actionLog.get(0));
    assertEquals("tail receives data", actionLog.get(1));
    assertEquals("tail writes in iteration 0", actionLog.get(2));
    assertEquals("head reads in iteration 0", actionLog.get(3));
    assertEquals("head sends data", actionLog.get(4));
    assertEquals("tail receives data", actionLog.get(5));
    assertEquals("tail writes in iteration 1", actionLog.get(6));
    assertEquals("head reads in iteration 1", actionLog.get(7));
    assertEquals("head sends data", actionLog.get(8));
    assertEquals("tail receives data", actionLog.get(9));
    assertEquals("tail writes in iteration 2", actionLog.get(10));
    assertEquals("head reads in iteration 2", actionLog.get(11));
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ArrayList(java.util.ArrayList) SerializedUpdateBuffer(org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 SerializedUpdateBuffer (org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 BlockingBackChannel (org.apache.flink.runtime.iterative.concurrent.BlockingBackChannel)1 Test (org.junit.Test)1