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);
}
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));
}
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"));
}
}
Aggregations