use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.
the class TestQueryContext method testChecksTotalMemoryOnUserMemoryAllocation.
@Test(expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = ".*Query exceeded per-node total memory limit of 20B.*")
public void testChecksTotalMemoryOnUserMemoryAllocation() {
try (LocalQueryRunner localQueryRunner = new LocalQueryRunner(TEST_SESSION)) {
QueryContext queryContext = new QueryContext(new QueryId("query"), // user memory limit
new DataSize(10, BYTE), // total memory limit
new DataSize(20, BYTE), new DataSize(10, BYTE), new DataSize(1, GIGABYTE), new MemoryPool(GENERAL_POOL, new DataSize(10, BYTE)), new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(0, BYTE), new SpillSpaceTracker(new DataSize(0, BYTE)), listJsonCodec(TaskMemoryReservationSummary.class));
queryContext.getQueryMemoryContext().initializeLocalMemoryContexts("test");
LocalMemoryContext systemMemoryContext = queryContext.getQueryMemoryContext().localSystemMemoryContext();
LocalMemoryContext userMemoryContext = queryContext.getQueryMemoryContext().localUserMemoryContext();
systemMemoryContext.setBytes(15);
userMemoryContext.setBytes(6);
}
}
use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.
the class TestMemoryTracking method testLocalSystemAllocations.
@Test
public void testLocalSystemAllocations() {
long pipelineLocalAllocation = 1_000_000;
long taskLocalAllocation = 10_000_000;
LocalMemoryContext pipelineLocalSystemMemoryContext = pipelineContext.localSystemMemoryContext();
pipelineLocalSystemMemoryContext.setBytes(pipelineLocalAllocation);
assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), pipelineLocalAllocation, 0, pipelineLocalAllocation);
LocalMemoryContext taskLocalSystemMemoryContext = taskContext.localSystemMemoryContext();
taskLocalSystemMemoryContext.setBytes(taskLocalAllocation);
assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), pipelineLocalAllocation + taskLocalAllocation, 0, taskLocalAllocation);
assertEquals(pipelineContext.getPipelineStats().getSystemMemoryReservationInBytes(), pipelineLocalAllocation, "task level allocations should not be visible at the pipeline level");
pipelineLocalSystemMemoryContext.setBytes(pipelineLocalSystemMemoryContext.getBytes() - pipelineLocalAllocation);
assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), taskLocalAllocation, 0, 0);
taskLocalSystemMemoryContext.setBytes(taskLocalSystemMemoryContext.getBytes() - taskLocalAllocation);
assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), 0, 0, 0);
}
use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.
the class TestMemoryTracking method testTrySetBytes.
@Test
public void testTrySetBytes() {
LocalMemoryContext localMemoryContext = operatorContext.localUserMemoryContext();
assertTrue(localMemoryContext.trySetBytes(100_000_000));
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
assertTrue(localMemoryContext.trySetBytes(200_000_000));
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 200_000_000, 0, 0);
assertTrue(localMemoryContext.trySetBytes(100_000_000));
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
// allocating more than the pool size should fail and we should have the same stats as before
assertFalse(localMemoryContext.trySetBytes(memoryPool.getMaxBytes() + 1));
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 0, 0);
}
use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.
the class TestMemoryTracking method testRevocableMemoryAllocations.
@Test
public void testRevocableMemoryAllocations() {
LocalMemoryContext systemMemory = operatorContext.newLocalSystemMemoryContext("test");
LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
LocalMemoryContext revocableMemory = operatorContext.localRevocableMemoryContext();
revocableMemory.setBytes(100_000_000);
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 0, 100_000_000, 0);
userMemory.setBytes(100_000_000);
systemMemory.setBytes(100_000_000);
revocableMemory.setBytes(200_000_000);
assertStats(operatorContext.getOperatorStats(), driverContext.getDriverStats(), pipelineContext.getPipelineStats(), taskContext.getTaskStats(), 100_000_000, 200_000_000, 100_000_000);
}
use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.
the class TestOperatorMemoryRevocation method testOperatorMemoryRevocation.
@Test
public void testOperatorMemoryRevocation() {
AtomicInteger counter = new AtomicInteger();
OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
revocableMemoryContext.setBytes(1000);
operatorContext.setMemoryRevocationRequestListener(() -> counter.incrementAndGet());
operatorContext.requestMemoryRevoking();
assertTrue(operatorContext.isMemoryRevokingRequested());
assertEquals(counter.get(), 1);
// calling resetMemoryRevokingRequested() should clear the memory revoking requested flag
operatorContext.resetMemoryRevokingRequested();
assertFalse(operatorContext.isMemoryRevokingRequested());
operatorContext.requestMemoryRevoking();
assertEquals(counter.get(), 2);
assertTrue(operatorContext.isMemoryRevokingRequested());
}
Aggregations