Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speculative execution stats fixes #22076

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
import static io.trino.sql.planner.TopologicalOrderSubPlanVisitor.sortPlanInTopologicalOrder;
import static io.trino.tracing.TrinoAttributes.FAILURE_MESSAGE;
import static io.trino.util.Failures.toFailure;
import static java.lang.Math.clamp;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
Expand Down Expand Up @@ -1922,7 +1923,7 @@ public static class StageExecution
private boolean taskDescriptorLoadingActive;
private boolean exchangeClosed;

private final long startTime = System.currentTimeMillis();
private final long startTime;
private OptionalLong nonSpeculativeSwitchTime;

private MemoryRequirements initialMemoryRequirements;
Expand Down Expand Up @@ -1956,7 +1957,8 @@ private StageExecution(
this.schedulingPriority = schedulingPriority;
this.eager = eager;
this.speculative = speculative;
this.nonSpeculativeSwitchTime = speculative ? OptionalLong.empty() : OptionalLong.of(System.currentTimeMillis());
this.startTime = System.nanoTime();
this.nonSpeculativeSwitchTime = speculative ? OptionalLong.empty() : OptionalLong.of(startTime);
this.dynamicFilterService = requireNonNull(dynamicFilterService, "dynamicFilterService is null");
outputDataSize = new long[sinkPartitioningScheme.getPartitionCount()];
sinkOutputSelectorBuilder = ExchangeSourceOutputSelector.builder(ImmutableSet.of(exchange.getId()));
Expand Down Expand Up @@ -2033,7 +2035,7 @@ public void setSpeculative(boolean speculative)
{
checkArgument(!speculative || this.speculative, "cannot mark non-speculative stage as speculative");
if (this.speculative && !speculative) {
nonSpeculativeSwitchTime = OptionalLong.of(System.currentTimeMillis());
nonSpeculativeSwitchTime = OptionalLong.of(System.nanoTime());
}
this.speculative = speculative;
}
Expand Down Expand Up @@ -2367,16 +2369,12 @@ private void finish()

private void recordFinishStats()
{
long finishTime = System.currentTimeMillis();
long finishTime = System.nanoTime();
long nonSpeculativeSwitchTime = this.nonSpeculativeSwitchTime.orElse(finishTime);

double speculativeExecutionFraction = ((double) nonSpeculativeSwitchTime - (double) startTime) / ((double) finishTime - (double) startTime);
if (Double.isFinite(speculativeExecutionFraction)) {
stageExecutionStats.recordStageSpeculativeExecutionFraction(speculativeExecutionFraction);
}
else {
stageExecutionStats.recordStageSpeculativeExecutionFraction(1.0);
}
stageExecutionStats.recordStageSpeculativeExecutionFraction(clamp(
((double) nonSpeculativeSwitchTime - startTime) / (finishTime - startTime),
0.0,
1.0));
}

private void updateOutputSize(SpoolingOutputStats.Snapshot taskOutputStats)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ public void recordSourcesFinishedOnStageStart(int sourcesCount)
updateSourceOutputEstimationKindCounter("finished", sourcesCount);
}

@Managed
public void recordStageSpeculativeExecutionFraction(double fractionSpentSpeculative)
{
speculativeExecutionFractionDistribution.add((long) (fractionSpentSpeculative * EXECUTION_FRACTION_RESCALE_FACTOR));
}

@Managed
public DistributionStat getSpeculativeExecutionFraction()
{
return speculativeExecutionFractionDistribution;
}

private void updateSourceOutputEstimationKindCounter(String outputEstimationKind, int sourcesCount)
{
getCounterStat(outputEstimationKind).update(sourcesCount);
Expand Down
Loading