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