use of com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup in project presto by prestodb.
the class TestResourceGroups method testMemoryLimit.
@Test(timeOut = 10_000)
public void testMemoryLimit() {
RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, BYTE));
root.setMaxQueuedQueries(4);
root.setMaxRunningQueries(3);
MockQueryExecution query1 = new MockQueryExecution(1);
root.run(query1);
// Process the group to refresh stats
root.processQueuedQueries();
assertEquals(query1.getState(), RUNNING);
MockQueryExecution query2 = new MockQueryExecution(0);
root.run(query2);
assertEquals(query2.getState(), QUEUED);
MockQueryExecution query3 = new MockQueryExecution(0);
root.run(query3);
assertEquals(query3.getState(), QUEUED);
query1.complete();
root.processQueuedQueries();
assertEquals(query2.getState(), RUNNING);
assertEquals(query3.getState(), RUNNING);
}
use of com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup in project presto by prestodb.
the class TestResourceGroups method testPriorityScheduling.
@Test(timeOut = 10_000)
public void testPriorityScheduling() {
RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
root.setMaxQueuedQueries(100);
// Start with zero capacity, so that nothing starts running until we've added all the queries
root.setMaxRunningQueries(0);
root.setSchedulingPolicy(QUERY_PRIORITY);
InternalResourceGroup group1 = root.getOrCreateSubGroup("1");
group1.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
group1.setMaxQueuedQueries(100);
group1.setMaxRunningQueries(1);
InternalResourceGroup group2 = root.getOrCreateSubGroup("2");
group2.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
group2.setMaxQueuedQueries(100);
group2.setMaxRunningQueries(1);
SortedMap<Integer, MockQueryExecution> queries = new TreeMap<>();
Random random = new Random();
for (int i = 0; i < 100; i++) {
int priority;
do {
priority = random.nextInt(1_000_000) + 1;
} while (queries.containsKey(priority));
MockQueryExecution query = new MockQueryExecution(0, "query_id", priority);
if (random.nextBoolean()) {
group1.run(query);
} else {
group2.run(query);
}
queries.put(priority, query);
}
root.setMaxRunningQueries(1);
List<MockQueryExecution> orderedQueries = new ArrayList<>(queries.values());
reverse(orderedQueries);
for (MockQueryExecution query : orderedQueries) {
root.processQueuedQueries();
assertEquals(query.getState(), RUNNING);
query.complete();
}
}
Aggregations