Search in sources :

Example 16 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class QueryStateMachine method getBasicQueryInfo.

public BasicQueryInfo getBasicQueryInfo(Optional<BasicStageExecutionStats> rootStage) {
    // Query state must be captured first in order to provide a
    // correct view of the query.  For example, building this
    // information, the query could finish, and the task states would
    // never be visible.
    QueryState state = queryState.get();
    BasicStageExecutionStats stageStats = rootStage.orElse(EMPTY_STAGE_STATS);
    BasicQueryStats queryStats = new BasicQueryStats(queryStateTimer.getCreateTime(), getEndTime().orElse(null), queryStateTimer.getWaitingForPrerequisitesTime(), queryStateTimer.getQueuedTime(), queryStateTimer.getElapsedTime(), queryStateTimer.getExecutionTime(), getCurrentRunningTaskCount(), getPeakRunningTaskCount(), stageStats.getTotalDrivers(), stageStats.getQueuedDrivers(), stageStats.getRunningDrivers(), stageStats.getCompletedDrivers(), stageStats.getRawInputDataSize(), stageStats.getRawInputPositions(), stageStats.getCumulativeUserMemory(), stageStats.getCumulativeTotalMemory(), stageStats.getUserMemoryReservation(), stageStats.getTotalMemoryReservation(), succinctBytes(getPeakUserMemoryInBytes()), succinctBytes(getPeakTotalMemoryInBytes()), succinctBytes(getPeakTaskTotalMemory()), succinctBytes(getPeakNodeTotalMemory()), stageStats.getTotalCpuTime(), stageStats.getTotalScheduledTime(), stageStats.isFullyBlocked(), stageStats.getBlockedReasons(), stageStats.getTotalAllocation(), stageStats.getProgressPercentage());
    return new BasicQueryInfo(queryId, session.toSessionRepresentation(), Optional.of(resourceGroup), state, memoryPool.get().getId(), stageStats.isScheduled(), self, query, queryStats, failureCause.get(), queryType, warningCollector.getWarnings(), preparedQuery);
}
Also used : BasicQueryStats(com.facebook.presto.server.BasicQueryStats) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo)

Example 17 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class ResourceManagerClusterStatusSender method sendQueryHeartbeat.

private void sendQueryHeartbeat(ManagedQueryExecution queryExecution, long sequenceId) {
    BasicQueryInfo basicQueryInfo = queryExecution.getBasicQueryInfo();
    String nodeIdentifier = internalNodeManager.getCurrentNode().getNodeIdentifier();
    getResourceManagers().forEach(hostAndPort -> resourceManagerClient.get(Optional.of(hostAndPort.toString())).queryHeartbeat(nodeIdentifier, basicQueryInfo, sequenceId));
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo)

Example 18 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class DistributedClusterStatsResource method getClusterStats.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterStats() {
    long runningQueries = 0;
    long blockedQueries = 0;
    long queuedQueries = 0;
    long activeNodes = internalNodeManager.getNodes(NodeState.ACTIVE).size();
    if (!isIncludeCoordinator) {
        activeNodes -= internalNodeManager.getCoordinators().size();
    }
    activeNodes -= internalNodeManager.getResourceManagers().size();
    long runningDrivers = 0;
    long runningTasks = 0;
    double memoryReservation = 0;
    long totalInputRows = 0;
    long totalInputBytes = 0;
    long totalCpuTimeSecs = 0;
    for (BasicQueryInfo query : clusterStateProvider.getClusterQueries()) {
        if (query.getState() == QueryState.QUEUED) {
            queuedQueries++;
        } else if (query.getState() == QueryState.RUNNING) {
            if (query.getQueryStats().isFullyBlocked()) {
                blockedQueries++;
            } else {
                runningQueries++;
            }
        }
        if (!query.getState().isDone()) {
            totalInputBytes += query.getQueryStats().getRawInputDataSize().toBytes();
            totalInputRows += query.getQueryStats().getRawInputPositions();
            totalCpuTimeSecs += query.getQueryStats().getTotalCpuTime().getValue(SECONDS);
            memoryReservation += query.getQueryStats().getUserMemoryReservation().toBytes();
            runningDrivers += query.getQueryStats().getRunningDrivers();
            runningTasks += query.getQueryStats().getRunningTasks();
        }
    }
    // TODO compute adjusted queue size on RM
    return Response.ok(new ClusterStatsResource.ClusterStats(runningQueries, blockedQueries, queuedQueries, activeNodes, runningDrivers, runningTasks, memoryReservation, totalInputRows, totalInputBytes, totalCpuTimeSecs, 0)).build();
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class DistributedQueryResource method getAllQueryInfo.

@GET
public Response getAllQueryInfo(@QueryParam("state") String stateFilter, @QueryParam("limit") Integer limitFilter) {
    QueryState expectedState = stateFilter == null ? null : QueryState.valueOf(stateFilter.toUpperCase(Locale.ENGLISH));
    List<BasicQueryInfo> queries;
    int limit = firstNonNull(limitFilter, Integer.MAX_VALUE);
    if (limit <= 0) {
        throw new WebApplicationException(Response.status(BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity(format("Parameter 'limit' for getAllQueryInfo must be positive. Got %d.", limit)).build());
    }
    if (stateFilter == null) {
        queries = clusterStateProvider.getClusterQueries();
    } else {
        ImmutableList.Builder<BasicQueryInfo> builder = ImmutableList.builder();
        for (BasicQueryInfo queryInfo : clusterStateProvider.getClusterQueries()) {
            if (queryInfo.getState() == expectedState) {
                builder.add(queryInfo);
            }
        }
        queries = builder.build();
    }
    queries = new ArrayList<>(queries);
    if (limit < queries.size()) {
        queries.sort(QUERIES_ORDERING);
    } else {
        limit = queries.size();
    }
    queries = ImmutableList.copyOf(queries.subList(0, limit));
    return Response.ok(queries).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryState(com.facebook.presto.execution.QueryState) GET(javax.ws.rs.GET)

Example 20 with BasicQueryInfo

use of com.facebook.presto.server.BasicQueryInfo in project presto by prestodb.

the class QuerySystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    Builder table = InMemoryRecordSet.builder(QUERY_TABLE);
    List<QueryInfo> queryInfos = queryManager.getQueries().stream().map(BasicQueryInfo::getQueryId).map(queryId -> {
        try {
            return queryManager.getFullQueryInfo(queryId);
        } catch (NoSuchElementException e) {
            return null;
        }
    }).filter(Objects::nonNull).collect(toImmutableList());
    for (QueryInfo queryInfo : queryInfos) {
        QueryStats queryStats = queryInfo.getQueryStats();
        table.addRow(queryInfo.getQueryId().toString(), queryInfo.getState().toString(), queryInfo.getSession().getUser(), queryInfo.getSession().getSource().orElse(null), queryInfo.getQuery(), queryInfo.getResourceGroupId().map(QuerySystemTable::resourceGroupIdToBlock).orElse(null), toMillis(queryStats.getQueuedTime()), toMillis(queryStats.getAnalysisTime()), toTimeStamp(queryStats.getCreateTime()), toTimeStamp(queryStats.getExecutionStartTime()), toTimeStamp(queryStats.getLastHeartbeat()), toTimeStamp(queryStats.getEndTime()));
    }
    return table.build().cursor();
}
Also used : QueryStats(com.facebook.presto.execution.QueryStats) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryInfo(com.facebook.presto.execution.QueryInfo) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)32 Test (org.testng.annotations.Test)19 QueryId (com.facebook.presto.spi.QueryId)12 QueryManager (com.facebook.presto.execution.QueryManager)9 TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)4 Session (com.facebook.presto.Session)3 DispatchManager (com.facebook.presto.dispatcher.DispatchManager)3 ExecutionFailureInfo (com.facebook.presto.execution.ExecutionFailureInfo)3 QueryInfo (com.facebook.presto.execution.QueryInfo)3 PrestoException (com.facebook.presto.spi.PrestoException)3 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)3 ImmutableList (com.google.common.collect.ImmutableList)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Assertions (com.facebook.airlift.testing.Assertions)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 QUERY_MAX_MEMORY (com.facebook.presto.SystemSessionProperties.QUERY_MAX_MEMORY)1