Search in sources :

Example 21 with MockManagedQueryExecution

use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.

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);
        queries.add(query);
        group.run(query);
    }
    return queries;
}
Also used : MockManagedQueryExecution(io.prestosql.execution.MockManagedQueryExecution) HashSet(java.util.HashSet)

Example 22 with MockManagedQueryExecution

use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.

the class TestResourceGroups method testSoftReservedMemory.

// new test case for softReservedMemory
@Test
public void testSoftReservedMemory() {
    InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimit(new DataSize(10, BYTE));
    root.setMaxQueuedQueries(10);
    root.setHardConcurrencyLimit(10);
    // three subgroup with setSoftReservedMemory = 1 byte
    InternalResourceGroup group1 = root.getOrCreateSubGroup("group1");
    group1.setSoftMemoryLimit(new DataSize(5, BYTE));
    group1.setMaxQueuedQueries(4);
    group1.setHardConcurrencyLimit(3);
    group1.setSoftReservedMemory(new DataSize(1, BYTE));
    InternalResourceGroup group2 = root.getOrCreateSubGroup("group2");
    group2.setSoftMemoryLimit(new DataSize(5, BYTE));
    group2.setMaxQueuedQueries(4);
    group2.setHardConcurrencyLimit(3);
    group2.setSoftReservedMemory(new DataSize(1, BYTE));
    InternalResourceGroup group3 = root.getOrCreateSubGroup("group3");
    group3.setSoftMemoryLimit(new DataSize(5, BYTE));
    group3.setMaxQueuedQueries(4);
    group3.setHardConcurrencyLimit(3);
    group3.setSoftReservedMemory(new DataSize(1, BYTE));
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(5);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(4);
    group1.run(query1);
    group2.run(query2);
    // group1 memory usage = 5M, group2 memory usage = 4M, group3 memory usage = 0
    assertEquals(query1.getState(), RUNNING);
    assertEquals(query2.getState(), RUNNING);
    root.processQueuedQueries();
    MockManagedQueryExecution extraQuery = new MockManagedQueryExecution(1);
    group2.run(extraQuery);
    assertEquals(extraQuery.getState(), QUEUED);
}
Also used : MockManagedQueryExecution(io.prestosql.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 23 with MockManagedQueryExecution

use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.

the class TestResourceGroups method testQueryKill.

@Test(timeOut = 10_000)
public void testQueryKill() {
    InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimit(new DataSize(1, BYTE));
    root.setMaxQueuedQueries(4);
    root.setHardConcurrencyLimit(3);
    root.setKillPolicy(KillPolicy.RECENT_QUERIES);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(2);
    root.run(query1);
    // Process the group to refresh stats
    root.processQueuedQueries();
    assertEquals(query1.getState(), FAILED);
}
Also used : MockManagedQueryExecution(io.prestosql.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 24 with MockManagedQueryExecution

use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.

the class TestResourceGroups method testQueryKillRecent.

@Test(timeOut = 10_000)
public void testQueryKillRecent() throws InterruptedException {
    InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimit(new DataSize(2, BYTE));
    root.setMaxQueuedQueries(4);
    root.setHardConcurrencyLimit(3);
    root.setKillPolicy(KillPolicy.RECENT_QUERIES);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(2);
    MILLISECONDS.sleep(1);
    root.run(query1);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(2);
    MILLISECONDS.sleep(1);
    root.run(query2);
    MockManagedQueryExecution query3 = new MockManagedQueryExecution(2);
    root.run(query3);
    // Process the group to refresh stats
    root.processQueuedQueries();
    assertEquals(query1.getState(), RUNNING);
    assertEquals(query2.getState(), FAILED);
    assertEquals(query3.getState(), FAILED);
}
Also used : MockManagedQueryExecution(io.prestosql.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 25 with MockManagedQueryExecution

use of io.prestosql.execution.MockManagedQueryExecution in project hetu-core by openlookeng.

the class TestResourceGroups method testHardCpuLimit.

@Test(timeOut = 10_000)
public void testHardCpuLimit() {
    InternalResourceGroup root = new InternalResourceGroup(Optional.empty(), "root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimit(new DataSize(1, BYTE));
    root.setHardCpuLimit(new Duration(1, SECONDS));
    root.setCpuQuotaGenerationMillisPerSecond(2000);
    root.setMaxQueuedQueries(1);
    root.setHardConcurrencyLimit(1);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(1, "query_id", 1, new Duration(2, SECONDS));
    root.run(query1);
    assertEquals(query1.getState(), RUNNING);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
    root.run(query2);
    assertEquals(query2.getState(), QUEUED);
    query1.complete();
    root.processQueuedQueries();
    assertEquals(query2.getState(), QUEUED);
    root.generateCpuQuota(2);
    root.processQueuedQueries();
    assertEquals(query2.getState(), RUNNING);
}
Also used : MockManagedQueryExecution(io.prestosql.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Aggregations

MockManagedQueryExecution (io.prestosql.execution.MockManagedQueryExecution)47 Test (org.testng.annotations.Test)43 DataSize (io.airlift.units.DataSize)27 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)5 Duration (io.airlift.units.Duration)4 ResourceGroupInfo (io.prestosql.server.ResourceGroupInfo)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ResourceGroupId (io.prestosql.spi.resourcegroups.ResourceGroupId)3 SharedQueryState (io.prestosql.statestore.SharedQueryState)3 Map (java.util.Map)3 QueryStateInfo (io.prestosql.server.QueryStateInfo)2 SharedResourceGroupState (io.prestosql.statestore.SharedResourceGroupState)2 BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InternalNode (io.prestosql.metadata.InternalNode)1 MockStateMap (io.prestosql.statestore.MockStateMap)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1