Search in sources :

Example 6 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class LowMemoryKillerTestingUtils method toNodeMemoryInfoList.

static List<MemoryInfo> toNodeMemoryInfoList(long memoryPoolMaxBytes, Map<String, Map<String, Long>> queries, Map<String, Map<String, Map<String, Long>>> tasks) {
    Map<InternalNode, NodeReservation> nodeReservations = new HashMap<>();
    for (Map.Entry<String, Map<String, Long>> entry : queries.entrySet()) {
        QueryId queryId = new QueryId(entry.getKey());
        Map<String, Long> reservationByNode = entry.getValue();
        for (Map.Entry<String, Long> nodeEntry : reservationByNode.entrySet()) {
            InternalNode node = new InternalNode(nodeEntry.getKey(), URI.create("http://localhost"), new NodeVersion("version"), false);
            long bytes = nodeEntry.getValue();
            if (bytes == 0) {
                continue;
            }
            nodeReservations.computeIfAbsent(node, ignored -> new NodeReservation()).add(queryId, bytes);
        }
    }
    ImmutableList.Builder<MemoryInfo> result = ImmutableList.builder();
    for (Map.Entry<InternalNode, NodeReservation> entry : nodeReservations.entrySet()) {
        NodeReservation nodeReservation = entry.getValue();
        MemoryPoolInfo memoryPoolInfo = new MemoryPoolInfo(memoryPoolMaxBytes, nodeReservation.getTotalReservedBytes(), 0, nodeReservation.getReservationByQuery(), ImmutableMap.of(), ImmutableMap.of());
        result.add(new MemoryInfo(7, memoryPoolInfo, tasksMemoryInfoForNode(entry.getKey().getNodeIdentifier(), tasks)));
    }
    return result.build();
}
Also used : QueryId(io.trino.spi.QueryId) ImmutableMap(com.google.common.collect.ImmutableMap) ListMultimap(com.google.common.collect.ListMultimap) HashMap(java.util.HashMap) TaskMemoryInfo(io.trino.TaskMemoryInfo) TaskId(io.trino.execution.TaskId) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) InternalNode(io.trino.metadata.InternalNode) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Map(java.util.Map) NodeVersion(io.trino.client.NodeVersion) URI(java.net.URI) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.trino.spi.QueryId) NodeVersion(io.trino.client.NodeVersion) TaskMemoryInfo(io.trino.TaskMemoryInfo) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) InternalNode(io.trino.metadata.InternalNode) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class ClusterMemoryManager method formatKillScenario.

private String formatKillScenario(List<MemoryInfo> nodes) {
    StringBuilder stringBuilder = new StringBuilder();
    for (MemoryInfo nodeMemoryInfo : nodes) {
        MemoryPoolInfo memoryPoolInfo = nodeMemoryInfo.getPool();
        stringBuilder.append("Query Kill Scenario: ");
        stringBuilder.append("MaxBytes ").append(memoryPoolInfo.getMaxBytes()).append(' ');
        stringBuilder.append("FreeBytes ").append(memoryPoolInfo.getFreeBytes() + memoryPoolInfo.getReservedRevocableBytes()).append(' ');
        stringBuilder.append("Queries ");
        Joiner.on(",").withKeyValueSeparator("=").appendTo(stringBuilder, memoryPoolInfo.getQueryMemoryReservations());
        stringBuilder.append("Tasks ");
        Joiner.on(",").withKeyValueSeparator("=").appendTo(stringBuilder, nodeMemoryInfo.getTasksMemoryInfo().asMap());
        stringBuilder.append('\n');
    }
    return stringBuilder.toString();
}
Also used : QueryMemoryInfo(io.trino.memory.LowMemoryKiller.QueryMemoryInfo) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo)

Example 8 with MemoryPoolInfo

use of io.trino.spi.memory.MemoryPoolInfo in project trino by trinodb.

the class TestFileResourceGroupConfigurationManager method testDocsExample.

@Test
public void testDocsExample() {
    // arbitrary uneven value for testing
    long memoryPoolSize = 31415926535900L;
    FileResourceGroupConfigurationManager manager = new FileResourceGroupConfigurationManager((listener) -> listener.accept(new MemoryPoolInfo(memoryPoolSize, 0, 0, ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of())), new FileResourceGroupConfig().setConfigFile("../../docs/src/main/sphinx/admin/resource-groups-example.json"));
    SelectionContext<ResourceGroupIdTemplate> selectionContext = match(manager, new SelectionCriteria(true, "Alice", ImmutableSet.of(), Optional.of("jdbc#powerfulbi"), ImmutableSet.of("hipri"), EMPTY_RESOURCE_ESTIMATES, Optional.of("select")));
    assertEquals(selectionContext.getResourceGroupId().toString(), "global.adhoc.bi-powerfulbi.Alice");
    TestingResourceGroup resourceGroup = new TestingResourceGroup(selectionContext.getResourceGroupId());
    manager.configure(resourceGroup, selectionContext);
    assertEquals(resourceGroup.getHardConcurrencyLimit(), 3);
    assertEquals(resourceGroup.getMaxQueuedQueries(), 10);
    assertEquals(resourceGroup.getSoftMemoryLimitBytes(), memoryPoolSize / 10);
}
Also used : SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) Test(org.testng.annotations.Test)

Aggregations

MemoryPoolInfo (io.trino.spi.memory.MemoryPoolInfo)8 QueryId (io.trino.spi.QueryId)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TaskMemoryInfo (io.trino.TaskMemoryInfo)3 TaskId (io.trino.execution.TaskId)3 List (java.util.List)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Iterables (com.google.common.collect.Iterables)1