Search in sources :

Example 6 with QueryContext

use of io.trino.memory.QueryContext in project trino by trinodb.

the class TestMemoryRevokingScheduler method newSqlTask.

private SqlTask newSqlTask(QueryId queryId) {
    QueryContext queryContext = getOrCreateQueryContext(queryId);
    TaskId taskId = new TaskId(new StageId(queryId.getId(), 0), idGeneator.incrementAndGet(), 0);
    URI location = URI.create("fake://task/" + taskId);
    return createSqlTask(taskId, location, "fake", queryContext, sqlTaskExecutionFactory, executor, sqlTask -> {
    }, DataSize.of(32, MEGABYTE), DataSize.of(200, MEGABYTE), new ExchangeManagerRegistry(new ExchangeHandleResolver()), new CounterStat());
}
Also used : CounterStat(io.airlift.stats.CounterStat) QueryContext(io.trino.memory.QueryContext) URI(java.net.URI) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver)

Example 7 with QueryContext

use of io.trino.memory.QueryContext in project trino by trinodb.

the class AbstractOperatorBenchmark method runOnce.

@Override
protected Map<String, Long> runOnce() {
    Session session = testSessionBuilder().setSystemProperty("optimizer.optimize-hash-generation", "true").setTransactionId(this.session.getRequiredTransactionId()).build();
    MemoryPool memoryPool = new MemoryPool(DataSize.of(1, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(DataSize.of(1, GIGABYTE));
    TaskContext taskContext = new QueryContext(new QueryId("test"), DataSize.of(256, MEGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), DataSize.of(256, MEGABYTE), spillSpaceTracker).addTaskContext(new TaskStateMachine(new TaskId(new StageId("query", 0), 0, 0), localQueryRunner.getExecutor()), session, () -> {
    }, false, false);
    CpuTimer cpuTimer = new CpuTimer();
    Map<String, Long> executionStats = execute(taskContext);
    CpuDuration executionTime = cpuTimer.elapsedTime();
    TaskStats taskStats = taskContext.getTaskStats();
    long inputRows = taskStats.getRawInputPositions();
    long inputBytes = taskStats.getRawInputDataSize().toBytes();
    long outputRows = taskStats.getOutputPositions();
    long outputBytes = taskStats.getOutputDataSize().toBytes();
    double inputMegaBytes = ((double) inputBytes) / MEGABYTE.inBytes();
    return ImmutableMap.<String, Long>builder().putAll(executionStats).put("elapsed_millis", executionTime.getWall().toMillis()).put("input_rows_per_second", (long) (inputRows / executionTime.getWall().getValue(SECONDS))).put("output_rows_per_second", (long) (outputRows / executionTime.getWall().getValue(SECONDS))).put("input_megabytes", (long) inputMegaBytes).put("input_megabytes_per_second", (long) (inputMegaBytes / executionTime.getWall().getValue(SECONDS))).put("wall_nanos", executionTime.getWall().roundTo(NANOSECONDS)).put("cpu_nanos", executionTime.getCpu().roundTo(NANOSECONDS)).put("user_nanos", executionTime.getUser().roundTo(NANOSECONDS)).put("input_rows", inputRows).put("input_bytes", inputBytes).put("output_rows", outputRows).put("output_bytes", outputBytes).buildOrThrow();
}
Also used : SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) TaskContext(io.trino.operator.TaskContext) TaskId(io.trino.execution.TaskId) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) QueryContext(io.trino.memory.QueryContext) TaskStats(io.trino.operator.TaskStats) TaskStateMachine(io.trino.execution.TaskStateMachine) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) CpuTimer(io.airlift.stats.CpuTimer) CpuDuration(io.airlift.stats.CpuTimer.CpuDuration) Session(io.trino.Session) MemoryPool(io.trino.memory.MemoryPool)

Example 8 with QueryContext

use of io.trino.memory.QueryContext in project trino by trinodb.

the class MemoryLocalQueryRunner method execute.

public List<Page> execute(@Language("SQL") String query) {
    MemoryPool memoryPool = new MemoryPool(DataSize.of(2, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(DataSize.of(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test"), DataSize.of(1, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), DataSize.of(4, GIGABYTE), spillSpaceTracker);
    TaskContext taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId(new StageId("query", 0), 0, 0), localQueryRunner.getExecutor()), localQueryRunner.getDefaultSession(), () -> {
    }, false, false);
    // Use NullOutputFactory to avoid coping out results to avoid affecting benchmark results
    ImmutableList.Builder<Page> output = ImmutableList.builder();
    List<Driver> drivers = localQueryRunner.createDrivers(query, new PageConsumerOperator.PageConsumerOutputFactory(types -> output::add), taskContext);
    boolean done = false;
    while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
            if (!driver.isFinished()) {
                driver.process();
                processed = true;
            }
        }
        done = !processed;
    }
    return output.build();
}
Also used : QueryId(io.trino.spi.QueryId) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) StageId(io.trino.execution.StageId) MemoryConnectorFactory(io.trino.plugin.memory.MemoryConnectorFactory) Page(io.trino.spi.Page) TaskStateMachine(io.trino.execution.TaskStateMachine) PageConsumerOperator(io.trino.testing.PageConsumerOperator) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) TaskContext(io.trino.operator.TaskContext) MemoryPool(io.trino.memory.MemoryPool) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) QueryContext(io.trino.memory.QueryContext) TaskId(io.trino.execution.TaskId) DataSize(io.airlift.units.DataSize) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Driver(io.trino.operator.Driver) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) Session(io.trino.Session) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) TaskContext(io.trino.operator.TaskContext) TaskId(io.trino.execution.TaskId) ImmutableList(com.google.common.collect.ImmutableList) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) Driver(io.trino.operator.Driver) Page(io.trino.spi.Page) QueryContext(io.trino.memory.QueryContext) TaskStateMachine(io.trino.execution.TaskStateMachine) PageConsumerOperator(io.trino.testing.PageConsumerOperator) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) MemoryPool(io.trino.memory.MemoryPool)

Aggregations

QueryContext (io.trino.memory.QueryContext)8 QueryId (io.trino.spi.QueryId)5 TestingGcMonitor (io.airlift.stats.TestingGcMonitor)4 MemoryPool (io.trino.memory.MemoryPool)4 SpillSpaceTracker (io.trino.spiller.SpillSpaceTracker)4 TaskContext (io.trino.operator.TaskContext)3 CounterStat (io.airlift.stats.CounterStat)2 Session (io.trino.Session)2 ExchangeManagerRegistry (io.trino.exchange.ExchangeManagerRegistry)2 SqlTask.createSqlTask (io.trino.execution.SqlTask.createSqlTask)2 StageId (io.trino.execution.StageId)2 TaskId (io.trino.execution.TaskId)2 TaskStateMachine (io.trino.execution.TaskStateMachine)2 ExchangeHandleResolver (io.trino.metadata.ExchangeHandleResolver)2 Page (io.trino.spi.Page)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CpuTimer (io.airlift.stats.CpuTimer)1