use of org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync in project flink by apache.
the class TaskManagerServices method fromConfiguration.
// --------------------------------------------------------------------------------------------
// Static factory methods for task manager services
// --------------------------------------------------------------------------------------------
/**
* Creates and returns the task manager services.
*
* @param resourceID resource ID of the task manager
* @param taskManagerServicesConfiguration task manager configuration
* @return task manager components
* @throws Exception
*/
public static TaskManagerServices fromConfiguration(TaskManagerServicesConfiguration taskManagerServicesConfiguration, ResourceID resourceID) throws Exception {
// pre-start checks
checkTempDirs(taskManagerServicesConfiguration.getTmpDirPaths());
final NetworkEnvironment network = createNetworkEnvironment(taskManagerServicesConfiguration);
network.start();
final TaskManagerLocation taskManagerLocation = new TaskManagerLocation(resourceID, taskManagerServicesConfiguration.getTaskManagerAddress(), network.getConnectionManager().getDataPort());
// this call has to happen strictly after the network stack has been initialized
final MemoryManager memoryManager = createMemoryManager(taskManagerServicesConfiguration);
// start the I/O manager, it will create some temp directories.
final IOManager ioManager = new IOManagerAsync(taskManagerServicesConfiguration.getTmpDirPaths());
final MetricRegistry metricRegistry = new MetricRegistry(taskManagerServicesConfiguration.getMetricRegistryConfiguration());
final TaskManagerMetricGroup taskManagerMetricGroup = new TaskManagerMetricGroup(metricRegistry, taskManagerLocation.getHostname(), taskManagerLocation.getResourceID().toString());
// Initialize the TM metrics
TaskExecutorMetricsInitializer.instantiateStatusMetrics(taskManagerMetricGroup, network);
final BroadcastVariableManager broadcastVariableManager = new BroadcastVariableManager();
final FileCache fileCache = new FileCache(taskManagerServicesConfiguration.getTmpDirPaths());
final List<ResourceProfile> resourceProfiles = new ArrayList<>(taskManagerServicesConfiguration.getNumberOfSlots());
for (int i = 0; i < taskManagerServicesConfiguration.getNumberOfSlots(); i++) {
resourceProfiles.add(new ResourceProfile(1.0, 42));
}
final TimerService<AllocationID> timerService = new TimerService<>(new ScheduledThreadPoolExecutor(1), taskManagerServicesConfiguration.getTimerServiceShutdownTimeout());
final TaskSlotTable taskSlotTable = new TaskSlotTable(resourceProfiles, timerService);
final JobManagerTable jobManagerTable = new JobManagerTable();
final JobLeaderService jobLeaderService = new JobLeaderService(taskManagerLocation);
return new TaskManagerServices(taskManagerLocation, memoryManager, ioManager, network, metricRegistry, taskManagerMetricGroup, broadcastVariableManager, fileCache, taskSlotTable, jobManagerTable, jobLeaderService);
}
use of org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync in project flink by apache.
the class BarrierBufferMassiveRandomTest method testWithTwoChannelsAndRandomBarriers.
@Test
public void testWithTwoChannelsAndRandomBarriers() {
IOManager ioMan = null;
try {
ioMan = new IOManagerAsync();
BufferPool pool1 = new NetworkBufferPool(100, PAGE_SIZE, MemoryType.HEAP).createBufferPool(100, 100);
BufferPool pool2 = new NetworkBufferPool(100, PAGE_SIZE, MemoryType.HEAP).createBufferPool(100, 100);
RandomGeneratingInputGate myIG = new RandomGeneratingInputGate(new BufferPool[] { pool1, pool2 }, new BarrierGenerator[] { new CountBarrier(100000), new RandomBarrier(100000) });
BarrierBuffer barrierBuffer = new BarrierBuffer(myIG, ioMan);
for (int i = 0; i < 2000000; i++) {
BufferOrEvent boe = barrierBuffer.getNextNonBlocked();
if (boe.isBuffer()) {
boe.getBuffer().recycle();
}
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (ioMan != null) {
ioMan.shutdown();
}
}
}
use of org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync in project flink by apache.
the class FileChannelStreamsTest method testCloseAndDeleteInputView.
@Test
public void testCloseAndDeleteInputView() {
try (IOManager ioManager = new IOManagerAsync()) {
MemoryManager memMan = MemoryManagerBuilder.newBuilder().build();
List<MemorySegment> memory = new ArrayList<MemorySegment>();
memMan.allocatePages(new DummyInvokable(), memory, 4);
FileIOChannel.ID channel = ioManager.createChannel();
// add some test data
try (FileWriter wrt = new FileWriter(channel.getPath())) {
wrt.write("test data");
}
BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
FileChannelInputView in = new FileChannelInputView(reader, memMan, memory, 9);
// read just something
in.readInt();
// close for the first time, make sure all memory returns
in.close();
assertTrue(memMan.verifyEmpty());
// close again, should not cause an exception
in.close();
// delete, make sure file is removed
in.closeAndDelete();
assertFalse(new File(channel.getPath()).exists());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync in project flink by apache.
the class SeekableFileChannelInputViewTest method testSeek.
@Test
public void testSeek() {
final int PAGE_SIZE = 16 * 1024;
final int NUM_RECORDS = 120000;
try (IOManager ioManager = new IOManagerAsync()) {
MemoryManager memMan = MemoryManagerBuilder.newBuilder().setMemorySize(4 * PAGE_SIZE).setPageSize(PAGE_SIZE).build();
List<MemorySegment> memory = new ArrayList<MemorySegment>();
memMan.allocatePages(new DummyInvokable(), memory, 4);
FileIOChannel.ID channel = ioManager.createChannel();
BlockChannelWriter<MemorySegment> writer = ioManager.createBlockChannelWriter(channel);
FileChannelOutputView out = new FileChannelOutputView(writer, memMan, memory, memMan.getPageSize());
// bytes)
for (int i = 0; i < NUM_RECORDS; i += 4) {
out.writeInt(i);
}
// close for the first time, make sure all memory returns
out.close();
assertTrue(memMan.verifyEmpty());
memMan.allocatePages(new DummyInvokable(), memory, 4);
SeekableFileChannelInputView in = new SeekableFileChannelInputView(ioManager, channel, memMan, memory, out.getBytesInLatestSegment());
// read first, complete
for (int i = 0; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to the middle of the 3rd page
int i = 2 * PAGE_SIZE + PAGE_SIZE / 4;
in.seek(i);
for (; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to the end
i = 120000 - 4;
in.seek(i);
for (; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to the beginning
i = 0;
in.seek(i);
for (; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to after a page
i = PAGE_SIZE;
in.seek(i);
for (; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to after a page
i = 3 * PAGE_SIZE;
in.seek(i);
for (; i < NUM_RECORDS; i += 4) {
assertEquals(i, in.readInt());
}
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek to the end
i = NUM_RECORDS;
in.seek(i);
try {
in.readInt();
fail("should throw EOF exception");
} catch (EOFException ignored) {
}
// seek out of bounds
try {
in.seek(-10);
fail("should throw an exception");
} catch (IllegalArgumentException ignored) {
}
try {
in.seek(NUM_RECORDS + 1);
fail("should throw an exception");
} catch (IllegalArgumentException ignored) {
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync in project flink by apache.
the class NonReusingHashJoinIteratorITCase method beforeTest.
@SuppressWarnings("unchecked")
@Before
public void beforeTest() {
this.recordSerializer = TestData.getIntStringTupleSerializer();
this.record1Comparator = TestData.getIntStringTupleComparator();
this.record2Comparator = TestData.getIntStringTupleComparator();
this.recordPairComparator = new GenericPairComparator(record1Comparator, record2Comparator);
this.pairSerializer = new IntPairSerializer();
this.pairComparator = new TestData.IntPairComparator();
this.pairRecordPairComparator = new IntPairTuplePairComparator();
this.recordPairPairComparator = new TupleIntPairPairComparator();
this.memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_SIZE).build();
this.ioManager = new IOManagerAsync();
}
Aggregations