org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer Java Examples

The following examples show how to use org.apache.flink.runtime.iterative.io.SerializedUpdateBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IterationHeadTask.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: IterationHeadTask.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: IterationHeadTask.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: BlockingBackChannelTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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));
	}
 
Example #5
Source File: BlockingBackChannelTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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));
	}
 
Example #6
Source File: BlockingBackChannelTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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));
	}
 
Example #7
Source File: BlockingBackChannel.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public BlockingBackChannel(SerializedUpdateBuffer buffer) {
	this.buffer = buffer;
	queue = new ArrayBlockingQueue<SerializedUpdateBuffer>(1);
}
 
Example #8
Source File: BlockingBackChannel.java    From flink with Apache License 2.0 4 votes vote down vote up
public BlockingBackChannel(SerializedUpdateBuffer buffer) {
	this.buffer = buffer;
	queue = new ArrayBlockingQueue<SerializedUpdateBuffer>(1);
}
 
Example #9
Source File: BlockingBackChannel.java    From flink with Apache License 2.0 4 votes vote down vote up
public BlockingBackChannel(SerializedUpdateBuffer buffer) {
	this.buffer = buffer;
	queue = new ArrayBlockingQueue<SerializedUpdateBuffer>(1);
}