Search in sources :

Example 1 with ResourceEstimates

use of io.prestosql.spi.session.ResourceEstimates in project hetu-core by openlookeng.

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()));
    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.getPath().toString(), ZoneId.of(session.getTimeZoneKey().getId()), session.getLocale(), resourceEstimates.build(), properties.build(), session.getPreparedStatements(), session.getIdentity().getRoles().entrySet().stream().collect(toImmutableMap(Entry::getKey, entry -> new ClientSelectedRole(ClientSelectedRole.Type.valueOf(entry.getValue().getType().toString()), entry.getValue().getRole()))), session.getIdentity().getExtraCredentials(), session.getTransactionId().map(Object::toString).orElse(null), clientRequestTimeout);
}
Also used : ResourceEstimates(io.prestosql.spi.session.ResourceEstimates) Entry(java.util.Map.Entry) ClientSelectedRole(io.prestosql.client.ClientSelectedRole) ClientSession(io.prestosql.client.ClientSession) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 2 with ResourceEstimates

use of io.prestosql.spi.session.ResourceEstimates in project hetu-core by openlookeng.

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"))))).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"))))).map(SelectionContext::getResourceGroupId), Optional.empty());
    assertEquals(smallQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), 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"))))).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"))))).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"))))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Also used : ResourceEstimates(io.prestosql.spi.session.ResourceEstimates) ResourceGroupId(io.prestosql.spi.resourcegroups.ResourceGroupId) Range(io.prestosql.plugin.resourcegroups.SelectorResourceEstimate.Range) Test(org.testng.annotations.Test)

Example 3 with ResourceEstimates

use of io.prestosql.spi.session.ResourceEstimates in project hetu-core by openlookeng.

the class TestQueues method testSelectorResourceEstimateBasedSelection.

@Test(timeOut = 240_000)
public void testSelectorResourceEstimateBasedSelection() throws Exception {
    try (DistributedQueryRunner queryRunner = createQueryRunner()) {
        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")))), LONG_LASTING_QUERY, createResourceGroupId("global", "small"));
        assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("600MB")))), LONG_LASTING_QUERY, createResourceGroupId("global", "other"));
        assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("4m")), 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")))), LONG_LASTING_QUERY, createResourceGroupId("global", "huge_memory"));
        assertResourceGroup(queryRunner, newSessionWithResourceEstimates(new ResourceEstimates(Optional.of(Duration.valueOf("100h")), Optional.empty(), Optional.of(DataSize.valueOf("4TB")))), LONG_LASTING_QUERY, createResourceGroupId("global", "other"));
    }
}
Also used : DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) ResourceEstimates(io.prestosql.spi.session.ResourceEstimates) ResourceGroupManagerPlugin(io.prestosql.plugin.resourcegroups.ResourceGroupManagerPlugin) Test(org.testng.annotations.Test)

Aggregations

ResourceEstimates (io.prestosql.spi.session.ResourceEstimates)3 Test (org.testng.annotations.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ClientSelectedRole (io.prestosql.client.ClientSelectedRole)1 ClientSession (io.prestosql.client.ClientSession)1 ResourceGroupManagerPlugin (io.prestosql.plugin.resourcegroups.ResourceGroupManagerPlugin)1 Range (io.prestosql.plugin.resourcegroups.SelectorResourceEstimate.Range)1 ResourceGroupId (io.prestosql.spi.resourcegroups.ResourceGroupId)1 DistributedQueryRunner (io.prestosql.tests.DistributedQueryRunner)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1