Search in sources :

Example 71 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class AbstractOperatorBenchmark method runOnce.

@Override
protected Map<String, Long> runOnce() {
    Session session = testSessionBuilder().setSystemProperty("optimizer.optimize-hash-generation", "true").build();
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(1, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(new DataSize(1, GIGABYTE));
    TaskContext taskContext = new QueryContext(new QueryId("test"), new DataSize(256, MEGABYTE), new DataSize(512, MEGABYTE), new DataSize(256, MEGABYTE), new DataSize(1, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(256, MEGABYTE), spillSpaceTracker, listJsonCodec(TaskMemoryReservationSummary.class)).addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0, 0), localQueryRunner.getExecutor()), session, Optional.empty(), false, false, false, 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.getRawInputDataSizeInBytes();
    long outputRows = taskStats.getOutputPositions();
    long outputBytes = taskStats.getOutputDataSizeInBytes();
    double inputMegaBytes = new DataSize(inputBytes, BYTE).getValue(MEGABYTE);
    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).build();
}
Also used : SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) TaskContext(com.facebook.presto.operator.TaskContext) TaskId(com.facebook.presto.execution.TaskId) QueryId(com.facebook.presto.spi.QueryId) QueryContext(com.facebook.presto.memory.QueryContext) TaskStats(com.facebook.presto.operator.TaskStats) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) CpuTimer(com.facebook.airlift.stats.CpuTimer) CpuDuration(com.facebook.airlift.stats.CpuTimer.CpuDuration) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) Session(com.facebook.presto.Session) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 72 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class ResourceManagerClusterStatusSender method registerQuery.

@Override
public void registerQuery(ManagedQueryExecution queryExecution) {
    QueryId queryId = queryExecution.getBasicQueryInfo().getQueryId();
    queries.computeIfAbsent(queryId, unused -> {
        AtomicLong sequenceId = new AtomicLong();
        PeriodicTaskExecutor taskExecutor = new PeriodicTaskExecutor(queryHeartbeatInterval.toMillis(), executor, () -> sendQueryHeartbeat(queryExecution, sequenceId.incrementAndGet()));
        taskExecutor.start();
        return taskExecutor;
    });
    queryExecution.addStateChangeListener(newState -> {
        if (newState.isDone()) {
            queries.computeIfPresent(queryId, (unused, queryHeartbeatSender) -> {
                queryHeartbeatSender.forceRun();
                queryHeartbeatSender.stop();
                return null;
            });
        }
    });
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PeriodicTaskExecutor(com.facebook.presto.util.PeriodicTaskExecutor) QueryId(com.facebook.presto.spi.QueryId)

Example 73 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class MemoryRevokingScheduler method revokeQueryMemory.

private void revokeQueryMemory(QueryContext queryContext, long maxTotalMemory) {
    QueryId queryId = queryContext.getQueryId();
    MemoryPool memoryPool = queryContext.getMemoryPool();
    // get a fresh value for queryTotalMemory in case it's changed (e.g. by a previous revocation request)
    long queryTotalMemory = getTotalQueryMemoryReservation(queryId, memoryPool);
    // order tasks by decreasing revocableMemory so that we don't spill more tasks than needed
    SortedMap<Long, TaskContext> queryTaskContextsMap = new TreeMap<>(Comparator.reverseOrder());
    queryContext.getAllTaskContexts().forEach(taskContext -> queryTaskContextsMap.put(taskContext.getTaskMemoryContext().getRevocableMemory(), taskContext));
    AtomicLong remainingBytesToRevoke = new AtomicLong(queryTotalMemory - maxTotalMemory);
    Collection<TaskContext> queryTaskContexts = queryTaskContextsMap.values();
    remainingBytesToRevoke.addAndGet(-MemoryRevokingSchedulerUtils.getMemoryAlreadyBeingRevoked(queryTaskContexts, remainingBytesToRevoke.get()));
    for (TaskContext taskContext : queryTaskContexts) {
        if (remainingBytesToRevoke.get() <= 0) {
            break;
        }
        taskContext.accept(new VoidTraversingQueryContextVisitor<AtomicLong>() {

            @Override
            public Void visitOperatorContext(OperatorContext operatorContext, AtomicLong remainingBytesToRevoke) {
                if (remainingBytesToRevoke.get() > 0) {
                    long revokedBytes = operatorContext.requestMemoryRevoking();
                    if (revokedBytes > 0) {
                        remainingBytesToRevoke.addAndGet(-revokedBytes);
                        log.debug("taskId=%s: requested revoking %s; remaining %s", taskContext.getTaskId(), revokedBytes, remainingBytesToRevoke);
                    }
                }
                return null;
            }
        }, remainingBytesToRevoke);
    }
}
Also used : TaskContext(com.facebook.presto.operator.TaskContext) QueryId(com.facebook.presto.spi.QueryId) TreeMap(java.util.TreeMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) OperatorContext(com.facebook.presto.operator.OperatorContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 74 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestMemoryRevokingScheduler method testQueryMemoryNotRevokedWhenNotEnabled.

@Test
public void testQueryMemoryNotRevokedWhenNotEnabled() throws Exception {
    // The various tasks created here use a small amount of system memory independent of what's set explicitly
    // in this test. Triggering spilling based on differences of thousands of bytes rather than hundreds
    // makes the test resilient to any noise that creates.
    QueryId queryId = new QueryId("query");
    // use a larger memory pool so that we don't trigger spilling due to filling the memory pool
    MemoryPool queryLimitMemoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(100, GIGABYTE));
    SqlTask sqlTask1 = newSqlTask(queryId, queryLimitMemoryPool);
    TestOperatorContext operatorContext11 = createTestingOperatorContexts(sqlTask1, "operator11");
    allOperatorContexts = ImmutableSet.of(operatorContext11);
    List<SqlTask> tasks = ImmutableList.of(sqlTask1);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(singletonList(queryLimitMemoryPool), () -> tasks, queryContexts::get, 1.0, 1.0, ORDER_BY_REVOCABLE_BYTES, false);
    try {
        scheduler.start();
        assertMemoryRevokingNotRequested();
        // exceed the query memory limit of 500KB
        operatorContext11.localRevocableMemoryContext().setBytes(600_000);
        scheduler.awaitAsynchronousCallbacksRun();
        assertMemoryRevokingNotRequested();
    } finally {
        scheduler.stop();
    }
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) QueryId(com.facebook.presto.spi.QueryId) DataSize(io.airlift.units.DataSize) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool) Test(org.testng.annotations.Test)

Example 75 with QueryId

use of com.facebook.presto.spi.QueryId in project presto by prestodb.

the class TestLocalDispatchQuery method testPrerequisitesQueryFinishedCalled.

@Test
public void testPrerequisitesQueryFinishedCalled() {
    QueryStateMachine stateMachine = createStateMachine();
    CountingEventListener eventListener = new CountingEventListener();
    CompletableFuture<?> prequisitesFuture = new CompletableFuture<>();
    AtomicBoolean queryFinishedCalled = new AtomicBoolean();
    LocalDispatchQuery query = new LocalDispatchQuery(stateMachine, createQueryMonitor(eventListener), immediateFuture(null), createClusterSizeMonitor(0), directExecutor(), dispatchQuery -> {
    }, execution -> {
    }, false, new QueryPrerequisites() {

        @Override
        public CompletableFuture<?> waitForPrerequisites(QueryId queryId, QueryPrerequisitesContext context, WarningCollector warningCollector) {
            return prequisitesFuture;
        }

        @Override
        public void queryFinished(QueryId queryId) {
            queryFinishedCalled.set(true);
        }
    });
    assertEquals(query.getBasicQueryInfo().getState(), WAITING_FOR_PREREQUISITES);
    assertFalse(eventListener.getQueryCompletedEvent().isPresent());
    query.startWaitingForPrerequisites();
    prequisitesFuture.complete(null);
    query.fail(new PrestoException(ABANDONED_QUERY, "foo"));
    assertTrue(queryFinishedCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) QueryStateMachine(com.facebook.presto.execution.QueryStateMachine) CompletableFuture(java.util.concurrent.CompletableFuture) QueryPrerequisitesContext(com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext) QueryId(com.facebook.presto.spi.QueryId) PrestoException(com.facebook.presto.spi.PrestoException) QueryPrerequisites(com.facebook.presto.spi.prerequisites.QueryPrerequisites) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Aggregations

QueryId (com.facebook.presto.spi.QueryId)121 Test (org.testng.annotations.Test)79 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)19 DataSize (io.airlift.units.DataSize)18 MemoryPoolId (com.facebook.presto.spi.memory.MemoryPoolId)17 Session (com.facebook.presto.Session)16 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)16 QueryManager (com.facebook.presto.execution.QueryManager)15 Identity (com.facebook.presto.spi.security.Identity)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ArrayList (java.util.ArrayList)11 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)10 PrestoException (com.facebook.presto.spi.PrestoException)10 ConnectorIdentity (com.facebook.presto.spi.security.ConnectorIdentity)10 List (java.util.List)10 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)9 MemoryPool (com.facebook.presto.memory.MemoryPool)9 ImmutableList (com.google.common.collect.ImmutableList)9 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)8 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)7