use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.
the class TestResourceGroups method testFairEligibility.
@Test(timeOut = 10_000)
public void testFairEligibility() {
InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
root.setMaxQueuedQueries(4);
root.setHardConcurrencyLimit(1);
InternalResourceGroup group1 = root.getOrCreateSubGroup("1");
group1.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
group1.setMaxQueuedQueries(4);
group1.setHardConcurrencyLimit(1);
InternalResourceGroup group2 = root.getOrCreateSubGroup("2");
group2.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
group2.setMaxQueuedQueries(4);
group2.setHardConcurrencyLimit(1);
InternalResourceGroup group3 = root.getOrCreateSubGroup("3");
group3.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
group3.setMaxQueuedQueries(4);
group3.setHardConcurrencyLimit(1);
MockManagedQueryExecution query1a = new MockManagedQueryExecution(0);
group1.run(query1a);
assertEquals(query1a.getState(), RUNNING);
MockManagedQueryExecution query1b = new MockManagedQueryExecution(0);
group1.run(query1b);
assertEquals(query1b.getState(), QUEUED);
MockManagedQueryExecution query2a = new MockManagedQueryExecution(0);
group2.run(query2a);
assertEquals(query2a.getState(), QUEUED);
MockManagedQueryExecution query2b = new MockManagedQueryExecution(0);
group2.run(query2b);
assertEquals(query2b.getState(), QUEUED);
MockManagedQueryExecution query3a = new MockManagedQueryExecution(0);
group3.run(query3a);
assertEquals(query3a.getState(), QUEUED);
query1a.complete();
root.processQueuedQueries();
// 2a and not 1b should have started, as group1 was not eligible to start a second query
assertEquals(query1b.getState(), QUEUED);
assertEquals(query2a.getState(), RUNNING);
assertEquals(query2b.getState(), QUEUED);
assertEquals(query3a.getState(), QUEUED);
query2a.complete();
root.processQueuedQueries();
assertEquals(query3a.getState(), RUNNING);
assertEquals(query2b.getState(), QUEUED);
assertEquals(query1b.getState(), QUEUED);
query3a.complete();
root.processQueuedQueries();
assertEquals(query1b.getState(), RUNNING);
assertEquals(query2b.getState(), QUEUED);
}
use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.
the class TestResourceGroups method testGetResourceGroupStateInfo.
@Test
public void testGetResourceGroupStateInfo() {
InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, GIGABYTE));
root.setMaxQueuedQueries(40);
root.setHardConcurrencyLimit(10);
root.setSchedulingPolicy(WEIGHTED);
InternalResourceGroup rootA = root.getOrCreateSubGroup("a");
rootA.setSoftMemoryLimit(new DataSize(10, MEGABYTE));
rootA.setMaxQueuedQueries(20);
rootA.setHardConcurrencyLimit(0);
InternalResourceGroup rootB = root.getOrCreateSubGroup("b");
rootB.setSoftMemoryLimit(new DataSize(5, MEGABYTE));
rootB.setMaxQueuedQueries(20);
rootB.setHardConcurrencyLimit(1);
rootB.setSchedulingWeight(2);
rootB.setSchedulingPolicy(QUERY_PRIORITY);
InternalResourceGroup rootAX = rootA.getOrCreateSubGroup("x");
rootAX.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootAX.setMaxQueuedQueries(10);
rootAX.setHardConcurrencyLimit(10);
InternalResourceGroup rootAY = rootA.getOrCreateSubGroup("y");
rootAY.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootAY.setMaxQueuedQueries(10);
rootAY.setHardConcurrencyLimit(10);
Set<MockManagedQueryExecution> queries = fillGroupTo(rootAX, ImmutableSet.of(), 5, false);
queries.addAll(fillGroupTo(rootAY, ImmutableSet.of(), 5, false));
queries.addAll(fillGroupTo(rootB, ImmutableSet.of(), 10, true));
ResourceGroupInfo rootInfo = root.getFullInfo();
assertEquals(rootInfo.getId(), root.getId());
assertEquals(rootInfo.getState(), CAN_RUN);
assertEquals(rootInfo.getSoftMemoryLimit(), root.getSoftMemoryLimit());
assertEquals(rootInfo.getMemoryUsage(), new DataSize(0, BYTE));
assertEquals(rootInfo.getSubGroups().size(), 2);
assertGroupInfoEquals(rootInfo.getSubGroups().get(0), rootA.getInfo());
assertEquals(rootInfo.getSubGroups().get(0).getId(), rootA.getId());
assertEquals(rootInfo.getSubGroups().get(0).getState(), CAN_QUEUE);
assertEquals(rootInfo.getSubGroups().get(0).getSoftMemoryLimit(), rootA.getSoftMemoryLimit());
assertEquals(rootInfo.getSubGroups().get(0).getHardConcurrencyLimit(), rootA.getHardConcurrencyLimit());
assertEquals(rootInfo.getSubGroups().get(0).getMaxQueuedQueries(), rootA.getMaxQueuedQueries());
assertEquals(rootInfo.getSubGroups().get(0).getNumEligibleSubGroups(), 2);
assertEquals(rootInfo.getSubGroups().get(0).getNumRunningQueries(), 0);
assertEquals(rootInfo.getSubGroups().get(0).getNumQueuedQueries(), 10);
assertGroupInfoEquals(rootInfo.getSubGroups().get(1), rootB.getInfo());
assertEquals(rootInfo.getSubGroups().get(1).getId(), rootB.getId());
assertEquals(rootInfo.getSubGroups().get(1).getState(), CAN_QUEUE);
assertEquals(rootInfo.getSubGroups().get(1).getSoftMemoryLimit(), rootB.getSoftMemoryLimit());
assertEquals(rootInfo.getSubGroups().get(1).getHardConcurrencyLimit(), rootB.getHardConcurrencyLimit());
assertEquals(rootInfo.getSubGroups().get(1).getMaxQueuedQueries(), rootB.getMaxQueuedQueries());
assertEquals(rootInfo.getSubGroups().get(1).getNumEligibleSubGroups(), 0);
assertEquals(rootInfo.getSubGroups().get(1).getNumRunningQueries(), 1);
assertEquals(rootInfo.getSubGroups().get(1).getNumQueuedQueries(), 9);
assertEquals(rootInfo.getSoftConcurrencyLimit(), root.getSoftConcurrencyLimit());
assertEquals(rootInfo.getHardConcurrencyLimit(), root.getHardConcurrencyLimit());
assertEquals(rootInfo.getMaxQueuedQueries(), root.getMaxQueuedQueries());
assertEquals(rootInfo.getNumQueuedQueries(), 19);
assertEquals(rootInfo.getRunningQueries().size(), 1);
QueryStateInfo queryInfo = rootInfo.getRunningQueries().get(0);
assertEquals(queryInfo.getResourceGroupId(), Optional.of(rootB.getId()));
}
use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.
the class TestResourceGroups method testSubgroupMemoryLimit.
@Test
public void testSubgroupMemoryLimit() {
InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(10, BYTE));
root.setMaxQueuedQueries(4);
root.setHardConcurrencyLimit(3);
InternalResourceGroup subgroup = root.getOrCreateSubGroup("subgroup");
subgroup.setSoftMemoryLimit(new DataSize(1, BYTE));
subgroup.setMaxQueuedQueries(4);
subgroup.setHardConcurrencyLimit(3);
MockManagedQueryExecution query1 = new MockManagedQueryExecution(2);
subgroup.run(query1);
// Process the group to refresh stats
root.processQueuedQueries();
assertEquals(query1.getState(), RUNNING);
MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
subgroup.run(query2);
assertEquals(query2.getState(), QUEUED);
MockManagedQueryExecution query3 = new MockManagedQueryExecution(0);
subgroup.run(query3);
assertEquals(query3.getState(), QUEUED);
query1.complete();
root.processQueuedQueries();
assertEquals(query2.getState(), RUNNING);
assertEquals(query3.getState(), RUNNING);
}
use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.
the class TestResourceGroups method testSoftCpuLimit.
@Test(timeOut = 10_000)
public void testSoftCpuLimit() {
InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, BYTE));
root.setSoftCpuLimit(new Duration(1, SECONDS));
root.setHardCpuLimit(new Duration(2, SECONDS));
root.setCpuQuotaGenerationMillisPerSecond(2000);
root.setMaxQueuedQueries(1);
root.setHardConcurrencyLimit(2);
MockManagedQueryExecution query1 = new MockManagedQueryExecution(1, "query_id", 1, new Duration(1, SECONDS));
root.run(query1);
assertEquals(query1.getState(), RUNNING);
MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
root.run(query2);
assertEquals(query2.getState(), RUNNING);
MockManagedQueryExecution query3 = new MockManagedQueryExecution(0);
root.run(query3);
assertEquals(query3.getState(), QUEUED);
query1.complete();
root.processQueuedQueries();
assertEquals(query2.getState(), RUNNING);
assertEquals(query3.getState(), QUEUED);
root.generateCpuQuota(2);
root.processQueuedQueries();
assertEquals(query2.getState(), RUNNING);
assertEquals(query3.getState(), RUNNING);
}
use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.
the class TestResourceGroups method testGetInfo.
@Test
public void testGetInfo() {
InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
root.setMaxQueuedQueries(40);
// Start with zero capacity, so that nothing starts running until we've added all the queries
root.setHardConcurrencyLimit(0);
root.setSchedulingPolicy(WEIGHTED);
InternalResourceGroup rootA = root.getOrCreateSubGroup("a");
rootA.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootA.setMaxQueuedQueries(20);
rootA.setHardConcurrencyLimit(2);
InternalResourceGroup rootB = root.getOrCreateSubGroup("b");
rootB.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootB.setMaxQueuedQueries(20);
rootB.setHardConcurrencyLimit(2);
rootB.setSchedulingWeight(2);
rootB.setSchedulingPolicy(QUERY_PRIORITY);
InternalResourceGroup rootAX = rootA.getOrCreateSubGroup("x");
rootAX.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootAX.setMaxQueuedQueries(10);
rootAX.setHardConcurrencyLimit(10);
InternalResourceGroup rootAY = rootA.getOrCreateSubGroup("y");
rootAY.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootAY.setMaxQueuedQueries(10);
rootAY.setHardConcurrencyLimit(10);
InternalResourceGroup rootBX = rootB.getOrCreateSubGroup("x");
rootBX.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootBX.setMaxQueuedQueries(10);
rootBX.setHardConcurrencyLimit(10);
InternalResourceGroup rootBY = rootB.getOrCreateSubGroup("y");
rootBY.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
rootBY.setMaxQueuedQueries(10);
rootBY.setHardConcurrencyLimit(10);
// Queue 40 queries (= maxQueuedQueries (40) + maxRunningQueries (0))
Set<MockManagedQueryExecution> queries = fillGroupTo(rootAX, ImmutableSet.of(), 10, false);
queries.addAll(fillGroupTo(rootAY, ImmutableSet.of(), 10, false));
queries.addAll(fillGroupTo(rootBX, ImmutableSet.of(), 10, true));
queries.addAll(fillGroupTo(rootBY, ImmutableSet.of(), 10, true));
ResourceGroupInfo info = root.getInfo();
assertEquals(info.getNumRunningQueries(), 0);
assertEquals(info.getNumQueuedQueries(), 40);
// root.maxRunningQueries = 4, root.a.maxRunningQueries = 2, root.b.maxRunningQueries = 2. Will have 4 queries running and 36 left queued.
root.setHardConcurrencyLimit(4);
root.processQueuedQueries();
info = root.getInfo();
assertEquals(info.getNumRunningQueries(), 4);
assertEquals(info.getNumQueuedQueries(), 36);
// Complete running queries
Iterator<MockManagedQueryExecution> iterator = queries.iterator();
while (iterator.hasNext()) {
MockManagedQueryExecution query = iterator.next();
if (query.getState() == RUNNING) {
query.complete();
iterator.remove();
}
}
// 4 more queries start running, 32 left queued.
root.processQueuedQueries();
info = root.getInfo();
assertEquals(info.getNumRunningQueries(), 4);
assertEquals(info.getNumQueuedQueries(), 32);
// root.maxRunningQueries = 10, root.a.maxRunningQueries = 2, root.b.maxRunningQueries = 2. Still only have 4 running queries and 32 left queued.
root.setHardConcurrencyLimit(10);
root.processQueuedQueries();
info = root.getInfo();
assertEquals(info.getNumRunningQueries(), 4);
assertEquals(info.getNumQueuedQueries(), 32);
// root.maxRunningQueries = 10, root.a.maxRunningQueries = 2, root.b.maxRunningQueries = 10. Will have 10 running queries and 26 left queued.
rootB.setHardConcurrencyLimit(10);
root.processQueuedQueries();
info = root.getInfo();
assertEquals(info.getNumRunningQueries(), 10);
assertEquals(info.getNumQueuedQueries(), 26);
}
Aggregations