Search in sources :

Example 16 with MockManagedQueryExecution

use of com.facebook.presto.execution.MockManagedQueryExecution 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(), ignored -> Optional.empty(), rg -> false);
    root.setSoftMemoryLimit(new DataSize(1, BYTE));
    root.setMaxQueuedQueries(4);
    root.setHardConcurrencyLimit(3);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(2);
    query1.startWaitingForPrerequisites();
    root.run(query1);
    // Process the group to refresh stats
    root.processQueuedQueries();
    assertEquals(query1.getState(), RUNNING);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
    query2.startWaitingForPrerequisites();
    root.run(query2);
    assertEquals(query2.getState(), QUEUED);
    MockManagedQueryExecution query3 = new MockManagedQueryExecution(0);
    query3.startWaitingForPrerequisites();
    root.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) MockManagedQueryExecution(com.facebook.presto.execution.MockManagedQueryExecution) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 17 with MockManagedQueryExecution

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

the class TestResourceGroups method testSetSchedulingPolicy.

@Test
public void testSetSchedulingPolicy() {
    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);
    assertEquals(root.getInfo().getNumEligibleSubGroups(), 2);
    assertEquals(root.getOrCreateSubGroup("1", true).getQueuedQueries(), 2);
    assertEquals(root.getOrCreateSubGroup("2", true).getQueuedQueries(), 1);
    assertEquals(root.getSchedulingPolicy(), FAIR);
    root.setSchedulingPolicy(QUERY_PRIORITY);
    assertEquals(root.getInfo().getNumEligibleSubGroups(), 2);
    assertEquals(root.getOrCreateSubGroup("1", true).getQueuedQueries(), 2);
    assertEquals(root.getOrCreateSubGroup("2", true).getQueuedQueries(), 1);
    assertEquals(root.getSchedulingPolicy(), QUERY_PRIORITY);
    assertEquals(root.getOrCreateSubGroup("1", true).getSchedulingPolicy(), QUERY_PRIORITY);
    assertEquals(root.getOrCreateSubGroup("2", true).getSchedulingPolicy(), QUERY_PRIORITY);
}
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 18 with MockManagedQueryExecution

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

the class TestResourceGroups method testQueueFull.

@Test(timeOut = 10_000)
public void testQueueFull() {
    RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    root.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    root.setMaxQueuedQueries(1);
    root.setHardConcurrencyLimit(1);
    MockManagedQueryExecution query1 = new MockManagedQueryExecution(0);
    query1.startWaitingForPrerequisites();
    root.run(query1);
    assertEquals(query1.getState(), RUNNING);
    MockManagedQueryExecution query2 = new MockManagedQueryExecution(0);
    query2.startWaitingForPrerequisites();
    root.run(query2);
    assertEquals(query2.getState(), QUEUED);
    MockManagedQueryExecution query3 = new MockManagedQueryExecution(0);
    query3.startWaitingForPrerequisites();
    root.run(query3);
    assertEquals(query3.getState(), FAILED);
    assertEquals(query3.getThrowable().getMessage(), "Too many queued queries for \"root\"");
}
Also used : 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 19 with MockManagedQueryExecution

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

the class TestResourceGroups method testGetBlockedQueuedQueries.

@Test
public void testGetBlockedQueuedQueries() {
    RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    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);
    InternalResourceGroup rootA = root.getOrCreateSubGroup("a", true);
    rootA.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootA.setMaxQueuedQueries(20);
    rootA.setHardConcurrencyLimit(8);
    InternalResourceGroup rootAX = rootA.getOrCreateSubGroup("x", true);
    rootAX.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootAX.setMaxQueuedQueries(10);
    rootAX.setHardConcurrencyLimit(8);
    InternalResourceGroup rootAY = rootA.getOrCreateSubGroup("y", true);
    rootAY.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootAY.setMaxQueuedQueries(10);
    rootAY.setHardConcurrencyLimit(5);
    InternalResourceGroup rootB = root.getOrCreateSubGroup("b", true);
    rootB.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootB.setMaxQueuedQueries(20);
    rootB.setHardConcurrencyLimit(8);
    InternalResourceGroup rootBX = rootB.getOrCreateSubGroup("x", true);
    rootBX.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootBX.setMaxQueuedQueries(10);
    rootBX.setHardConcurrencyLimit(8);
    InternalResourceGroup rootBY = rootB.getOrCreateSubGroup("y", true);
    rootBY.setSoftMemoryLimit(new DataSize(1, MEGABYTE));
    rootBY.setMaxQueuedQueries(10);
    rootBY.setHardConcurrencyLimit(5);
    // 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));
    assertEquals(root.getWaitingQueuedQueries(), 16);
    assertEquals(rootA.getWaitingQueuedQueries(), 13);
    assertEquals(rootAX.getWaitingQueuedQueries(), 10);
    assertEquals(rootAY.getWaitingQueuedQueries(), 10);
    assertEquals(rootB.getWaitingQueuedQueries(), 13);
    assertEquals(rootBX.getWaitingQueuedQueries(), 10);
    assertEquals(rootBY.getWaitingQueuedQueries(), 10);
    root.setHardConcurrencyLimit(20);
    root.processQueuedQueries();
    assertEquals(root.getWaitingQueuedQueries(), 0);
    assertEquals(rootA.getWaitingQueuedQueries(), 5);
    assertEquals(rootAX.getWaitingQueuedQueries(), 6);
    assertEquals(rootAY.getWaitingQueuedQueries(), 6);
    assertEquals(rootB.getWaitingQueuedQueries(), 5);
    assertEquals(rootBX.getWaitingQueuedQueries(), 6);
    assertEquals(rootBY.getWaitingQueuedQueries(), 6);
}
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)

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