Search in sources :

Example 1 with ResourceEstimates

use of com.facebook.presto.spi.session.ResourceEstimates in project presto by prestodb.

the class TestStaticSelector method testSelectorResourceEstimate.

@Test
public void testSelectorResourceEstimate() {
    ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
    StaticSelector smallQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.of(new Range<>(Optional.empty(), Optional.of(Duration.valueOf("5m")))), Optional.empty(), Optional.of(new Range<>(Optional.empty(), Optional.of(DataSize.valueOf("500MB")))))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(smallQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("400MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(smallQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("600MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    assertEquals(smallQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.empty(), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    StaticSelector largeQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.empty(), Optional.empty(), Optional.of(new Range<>(Optional.of(DataSize.valueOf("5TB")), Optional.empty())))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
    assertEquals(largeQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("100h")), Optional.empty(), Optional.of(DataSize.valueOf("4TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
    assertEquals(largeQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.empty(), Optional.empty(), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
    assertEquals(largeQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("1s")), Optional.of(Duration.valueOf("1s")), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Also used : ResourceEstimates(com.facebook.presto.spi.session.ResourceEstimates) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Range(com.facebook.presto.resourceGroups.SelectorResourceEstimate.Range) Test(org.testng.annotations.Test)

Example 2 with ResourceEstimates

use of com.facebook.presto.spi.session.ResourceEstimates in project presto by prestodb.

the class AbstractTestingPrestoClient method toClientSession.

private static ClientSession toClientSession(Session session, URI server, Duration clientRequestTimeout) {
    ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
    properties.putAll(session.getSystemProperties());
    for (Entry<String, Map<String, String>> connectorProperties : session.getUnprocessedCatalogProperties().entrySet()) {
        for (Entry<String, String> entry : connectorProperties.getValue().entrySet()) {
            properties.put(connectorProperties.getKey() + "." + entry.getKey(), entry.getValue());
        }
    }
    ImmutableMap.Builder<String, String> resourceEstimates = ImmutableMap.builder();
    ResourceEstimates estimates = session.getResourceEstimates();
    estimates.getExecutionTime().ifPresent(e -> resourceEstimates.put(EXECUTION_TIME, e.toString()));
    estimates.getCpuTime().ifPresent(e -> resourceEstimates.put(CPU_TIME, e.toString()));
    estimates.getPeakMemory().ifPresent(e -> resourceEstimates.put(PEAK_MEMORY, e.toString()));
    Map<String, String> serializedSessionFunctions = session.getSessionFunctions().entrySet().stream().collect(collectingAndThen(toMap(e -> SQL_FUNCTION_ID_JSON_CODEC.toJson(e.getKey()), e -> SQL_INVOKED_FUNCTION_JSON_CODEC.toJson(e.getValue())), ImmutableMap::copyOf));
    return new ClientSession(server, session.getIdentity().getUser(), session.getSource().orElse(null), session.getTraceToken(), session.getClientTags(), session.getClientInfo().orElse(null), session.getCatalog().orElse(null), session.getSchema().orElse(null), session.getTimeZoneKey().getId(), session.getLocale(), resourceEstimates.build(), properties.build(), session.getPreparedStatements(), session.getIdentity().getRoles(), session.getIdentity().getExtraCredentials(), session.getTransactionId().map(Object::toString).orElse(null), clientRequestTimeout, true, serializedSessionFunctions, ImmutableMap.of());
}
Also used : ResourceEstimates(com.facebook.presto.spi.session.ResourceEstimates) ClientSession(com.facebook.presto.client.ClientSession) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ResourceEstimates

use of com.facebook.presto.spi.session.ResourceEstimates in project presto by prestodb.

the class TestQueues method testSelectorResourceEstimateBasedSelection.

@Test(timeOut = 240_000)
public void testSelectorResourceEstimateBasedSelection() throws Exception {
    queryRunner.installPlugin(new ResourceGroupManagerPlugin());
    queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_resource_estimate_based_config.json")));
    assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("400MB")), Optional.empty())), LONG_LASTING_QUERY, createResourceGroupId("global", "small"));
    assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("600MB")), Optional.empty())), LONG_LASTING_QUERY, createResourceGroupId("global", "other"));
    assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.empty(), Optional.empty())), LONG_LASTING_QUERY, createResourceGroupId("global", "other"));
    assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("1s")), Optional.of(Duration.valueOf("1s")), Optional.of(DataSize.valueOf("6TB")), Optional.empty())), LONG_LASTING_QUERY, createResourceGroupId("global", "huge_memory"));
    assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("100h")), Optional.empty(), Optional.of(DataSize.valueOf("4TB")), Optional.empty())), LONG_LASTING_QUERY, createResourceGroupId("global", "other"));
}
Also used : ResourceEstimates(com.facebook.presto.spi.session.ResourceEstimates) ResourceGroupManagerPlugin(com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Aggregations

ResourceEstimates (com.facebook.presto.spi.session.ResourceEstimates)3 Test (org.testng.annotations.Test)2 ClientSession (com.facebook.presto.client.ClientSession)1 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)1 Range (com.facebook.presto.resourceGroups.SelectorResourceEstimate.Range)1 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)1