Search in sources :

Example 1 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution in project presto by prestodb.

the class TestResourceGroups method testSubgroupMemoryLimit.

@Test
public void testSubgroupMemoryLimit() {
    RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    root.setSoftMemoryLimit(new DataSize(10, BYTE));
    root.setMaxQueuedQueries(4);
    root.setHardConcurrencyLimit(3);
    InternalResourceGroup subgroup = root.getOrCreateSubGroup("subgroup", true);
    subgroup.setSoftMemoryLimit(new DataSize(1, BYTE));
    subgroup.setMaxQueuedQueries(4);
    subgroup.setHardConcurrencyLimit(3);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(2);
    query1.startWaitingForPrerequisites();
    subgroup.run(query1);
    // Process the group to refresh stats
    root.processQueuedQueries();
    assertEquals(query1.getState(), RUNNING);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
    query2.startWaitingForPrerequisites();
    subgroup.run(query2);
    assertEquals(query2.getState(), QUEUED);
    MockManagedQueryExecution query3 = new MockManagedQueryExecution(0);
    query3.startWaitingForPrerequisites();
    subgroup.run(query3);
    assertEquals(query3.getState(), QUEUED);
    query1.complete();
    root.processQueuedQueries();
    assertEquals(query2.getState(), RUNNING);
    assertEquals(query3.getState(), RUNNING);
}
Also used : RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 2 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution in project presto by prestodb.

the class TestResourceGroups method testFairQueuing.

@Test(timeOut = 10_000)
public void testFairQueuing() {
    RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    root.setMaxQueuedQueries(4);
    root.setHardConcurrencyLimit(1);
    InternalResourceGroup group1 = root.getOrCreateSubGroup("1", true);
    group1.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    group1.setMaxQueuedQueries(4);
    group1.setHardConcurrencyLimit(2);
    InternalResourceGroup group2 = root.getOrCreateSubGroup("2", true);
    group2.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    group2.setMaxQueuedQueries(4);
    group2.setHardConcurrencyLimit(2);
    MockManagedQueryExecution query1a = new MockManagedQueryExecution(0);
    query1a.startWaitingForPrerequisites();
    group1.run(query1a);
    assertEquals(query1a.getState(), RUNNING);
    MockManagedQueryExecution query1b = new MockManagedQueryExecution(0);
    query1b.startWaitingForPrerequisites();
    group1.run(query1b);
    assertEquals(query1b.getState(), QUEUED);
    MockManagedQueryExecution query1c = new MockManagedQueryExecution(0);
    query1c.startWaitingForPrerequisites();
    group1.run(query1c);
    assertEquals(query1c.getState(), QUEUED);
    MockManagedQueryExecution query2a = new MockManagedQueryExecution(0);
    query2a.startWaitingForPrerequisites();
    group2.run(query2a);
    assertEquals(query2a.getState(), QUEUED);
    query1a.complete();
    root.processQueuedQueries();
    // 1b and not 2a should have started, as it became queued first and group1 was eligible to run more
    assertEquals(query1b.getState(), RUNNING);
    assertEquals(query1c.getState(), QUEUED);
    assertEquals(query2a.getState(), QUEUED);
    // 2a and not 1c should have started, as all eligible sub groups get fair sharing
    query1b.complete();
    root.processQueuedQueries();
    assertEquals(query2a.getState(), RUNNING);
    assertEquals(query1c.getState(), QUEUED);
}
Also used : RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 3 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution in project presto by prestodb.

the class TestResourceGroups method fillGroupTo.

private static Set<MockManagedQueryExecution> fillGroupTo(InternalResourceGroup group, Set<MockManagedQueryExecution> existingQueries, int count, boolean queryPriority) {
    int existingCount = existingQueries.size();
    Set<MockManagedQueryExecution> queries = new HashSet<>(existingQueries);
    for (int i = 0; i < count - existingCount; i++) {
        MockManagedQueryExecution query = new MockManagedQueryExecution(0, group.getId().toString().replace(".", "") + Integer.toString(i), queryPriority ? i + 1 : 1, new Duration(0, MILLISECONDS), group.getId());
        queries.add(query);
        group.run(query);
    }
    return queries;
}
Also used : MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) Duration(io.airlift.units.Duration) HashSet(java.util.HashSet)

Example 4 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution in project presto by prestodb.

the class TestResourceGroups method testWeightedFairSchedulingEqualWeights.

@Test(timeOut = 10_000)
public void testWeightedFairSchedulingEqualWeights() {
    RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    root.setMaxQueuedQueries(50);
    // Start with zero capacity, so that nothing starts running until we've added all the queries
    root.setHardConcurrencyLimit(0);
    root.setSchedulingPolicy(WEIGHTED_FAIR);
    InternalResourceGroup group1 = root.getOrCreateSubGroup("1", true);
    group1.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    group1.setMaxQueuedQueries(50);
    group1.setHardConcurrencyLimit(2);
    group1.setSoftConcurrencyLimit(2);
    group1.setSchedulingWeight(1);
    InternalResourceGroup group2 = root.getOrCreateSubGroup("2", true);
    group2.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    group2.setMaxQueuedQueries(50);
    group2.setHardConcurrencyLimit(2);
    group2.setSoftConcurrencyLimit(2);
    group2.setSchedulingWeight(1);
    InternalResourceGroup group3 = root.getOrCreateSubGroup("3", true);
    group3.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    group3.setMaxQueuedQueries(50);
    group3.setHardConcurrencyLimit(2);
    group3.setSoftConcurrencyLimit(2);
    group3.setSchedulingWeight(2);
    Set<MockManagedQueryExecution> group1Queries = fillGroupTo(group1, ImmutableSet.of(), 4);
    Set<MockManagedQueryExecution> group2Queries = fillGroupTo(group2, ImmutableSet.of(), 4);
    Set<MockManagedQueryExecution> group3Queries = fillGroupTo(group3, ImmutableSet.of(), 4);
    root.setHardConcurrencyLimit(4);
    int group1Ran = 0;
    int group2Ran = 0;
    int group3Ran = 0;
    for (int i = 0; i < 1000; i++) {
        group1Ran += completeGroupQueries(group1Queries);
        group2Ran += completeGroupQueries(group2Queries);
        group3Ran += completeGroupQueries(group3Queries);
        root.processQueuedQueries();
        group1Queries = fillGroupTo(group1, group1Queries, 4);
        group2Queries = fillGroupTo(group2, group2Queries, 4);
        group3Queries = fillGroupTo(group3, group3Queries, 4);
    }
    // group 3 should run approximately 2x the number of queries of 1 and 2
    BinomialDistribution binomial = new BinomialDistribution(4000, 1.0 / 4.0);
    int lowerBound = binomial.inverseCumulativeProbability(0.000001);
    int upperBound = binomial.inverseCumulativeProbability(0.999999);
    assertBetweenInclusive(group1Ran, lowerBound, upperBound);
    assertBetweenInclusive(group2Ran, lowerBound, upperBound);
    assertBetweenInclusive(group3Ran, 2 * lowerBound, 2 * upperBound);
}
Also used : RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution) Test(org.testng.annotations.Test)

Example 5 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution in project presto by prestodb.

the class TestResourceGroups method completeGroupQueries.

private static int completeGroupQueries(Set<MockManagedQueryExecution> groupQueries) {
    int groupRan = 0;
    for (Iterator<MockManagedQueryExecution> iterator = groupQueries.iterator(); iterator.hasNext(); ) {
        MockManagedQueryExecution query = iterator.next();
        if (query.getState() == RUNNING) {
            query.complete();
            iterator.remove();
            groupRan++;
        }
    }
    return groupRan;
}
Also used : MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution)

Aggregations

MockManagedQueryExecution (com.facebook.presto.execution.MockManagedQueryExecution)19 Test (org.testng.annotations.Test)17 RootInternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)16 DataSize (io.airlift.units.DataSize)16 Duration (io.airlift.units.Duration)3 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)2 BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)2 QueryStateInfo (com.facebook.presto.server.QueryStateInfo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 AfterTest (org.testng.annotations.AfterTest)1 BeforeTest (org.testng.annotations.BeforeTest)1