-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Time framed thread-pool utilization #131898
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
Open
mhl-b
wants to merge
29
commits into
elastic:main
Choose a base branch
from
mhl-b:framed-thread-pool-utilization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
18ec741
framed-time-tracker
mhl-b 80f792f
jmh
mhl-b 8345da4
tests
mhl-b 2421600
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b cb531b9
Update docs/changelog/131898.yaml
mhl-b ab04cc6
assertion fix
mhl-b deea172
Merge branch 'framed-thread-pool-utilization' of github.com:mhl-b/ela…
mhl-b 454a871
duration toNanos
mhl-b 5228abd
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b a87a7c4
comments
mhl-b 8850789
[CI] Auto commit changes from spotless
3d66e86
Micro-ize the benchmark
nicktindall efa48b4
Use average instead of sample
nicktindall 872d7cd
Merge pull request #2 from nicktindall/framed-thread-pool-utilization_bm
mhl-b 33173fb
non-locking counting
mhl-b f3c81db
rwlock
mhl-b c281e8d
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b 5771c46
cleanup
mhl-b 12ef5e4
back to syncronized
mhl-b d006ed5
[CI] Auto commit changes from spotless
3caae03
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b 18115c4
Merge branch 'framed-thread-pool-utilization' of github.com:mhl-b/ela…
mhl-b 3816a50
non-locking frame windows
mhl-b fd0b91a
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b 225280a
nits
mhl-b 36374fc
window and frames
mhl-b 3dd755e
[CI] Auto commit changes from spotless
0fbbd81
Merge remote-tracking branch 'upstream/main' into framed-thread-pool-…
mhl-b c1c33ac
fix
mhl-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...va/org/elasticsearch/benchmark/common/util/concurrent/ThreadPoolUtilizationBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.benchmark.common.util.concurrent; | ||
|
||
import org.elasticsearch.common.util.concurrent.TaskExecutionTimeTrackingEsThreadPoolExecutor; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Group; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Threads(Threads.MAX) | ||
@BenchmarkMode(Mode.SampleTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.MINUTES) | ||
@State(Scope.Benchmark) | ||
@Fork(1) | ||
public class ThreadPoolUtilizationBenchmark { | ||
|
||
@Param({ "10000" }) | ||
private int callIntervalTicks; | ||
|
||
/** | ||
* This makes very little difference, all the overhead is in the synchronization | ||
*/ | ||
@Param({ "1000" }) | ||
private int frameDurationMs; | ||
|
||
@Param({ "10000" }) | ||
private int reportingDurationMs; | ||
|
||
private TaskExecutionTimeTrackingEsThreadPoolExecutor.FramedTimeTracker timeTracker; | ||
|
||
@Setup | ||
public void setup() { | ||
timeTracker = new TaskExecutionTimeTrackingEsThreadPoolExecutor.FramedTimeTracker( | ||
Duration.ofMillis(reportingDurationMs).toNanos(), | ||
Duration.ofMillis(frameDurationMs).toNanos(), | ||
System::nanoTime | ||
); | ||
} | ||
|
||
@Benchmark | ||
public void baseline() { | ||
Blackhole.consumeCPU(callIntervalTicks); | ||
} | ||
|
||
@Group("StartAndEnd") | ||
@Benchmark | ||
public void startAndStopTasks() { | ||
timeTracker.startTask(); | ||
Blackhole.consumeCPU(callIntervalTicks); | ||
timeTracker.endTask(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 131898 | ||
summary: Time framed thread-pool utilization | ||
area: Allocation | ||
type: enhancement | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import org.elasticsearch.core.SuppressForbidden; | ||
import org.elasticsearch.node.Node; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.AbstractExecutorService; | ||
|
@@ -576,80 +577,80 @@ public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { | |
} | ||
} | ||
|
||
public static class TaskTrackingConfig { | ||
/** | ||
* @param trackExecutionTime Whether to track execution stats | ||
* @param trackUtilization Enables thread-pool utilization metrics | ||
* @param utilizationReportingInterval When utilization is enabled, specifies interval for reporting utilization, default 30 seconds | ||
* @param utilizationSamplingInterval When utilization is enabled, specifies sample interval, default 1 second | ||
* @param trackOngoingTasks Whether to track ongoing task execution time, not just finished tasks | ||
* @param trackMaxQueueLatency Whether to track max queue latency | ||
* @param executionTimeEwmaAlpha The alpha seed for execution time EWMA (ExponentiallyWeightedMovingAverage) | ||
*/ | ||
public record TaskTrackingConfig( | ||
boolean trackExecutionTime, | ||
boolean trackUtilization, | ||
Duration utilizationReportingInterval, | ||
Duration utilizationSamplingInterval, | ||
boolean trackOngoingTasks, | ||
boolean trackMaxQueueLatency, | ||
double executionTimeEwmaAlpha | ||
) { | ||
|
||
// This is a random starting point alpha. | ||
public static final double DEFAULT_EXECUTION_TIME_EWMA_ALPHA_FOR_TEST = 0.3; | ||
|
||
private final boolean trackExecutionTime; | ||
private final boolean trackOngoingTasks; | ||
private final boolean trackMaxQueueLatency; | ||
private final double executionTimeEwmaAlpha; | ||
public static final Duration DEFAULT_UTILIZATION_INTERVAL = Duration.ofSeconds(30); | ||
public static final Duration DEFAULT_UTILIZATION_SAMPLING_INTERVAL = Duration.ofSeconds(1); | ||
|
||
public static final TaskTrackingConfig DO_NOT_TRACK = new TaskTrackingConfig( | ||
false, | ||
false, | ||
DEFAULT_UTILIZATION_INTERVAL, | ||
DEFAULT_UTILIZATION_SAMPLING_INTERVAL, | ||
false, | ||
false, | ||
DEFAULT_EXECUTION_TIME_EWMA_ALPHA_FOR_TEST | ||
); | ||
|
||
public static final TaskTrackingConfig DEFAULT = new TaskTrackingConfig( | ||
true, | ||
true, | ||
DEFAULT_UTILIZATION_INTERVAL, | ||
DEFAULT_UTILIZATION_SAMPLING_INTERVAL, | ||
false, | ||
false, | ||
DEFAULT_EXECUTION_TIME_EWMA_ALPHA_FOR_TEST | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is peripheral but I think we should move to using the builder for |
||
|
||
/** | ||
* @param trackExecutionTime Whether to track execution stats | ||
* @param trackOngoingTasks Whether to track ongoing task execution time, not just finished tasks | ||
* @param trackMaxQueueLatency Whether to track max queue latency. | ||
* @param executionTimeEWMAAlpha The alpha seed for execution time EWMA (ExponentiallyWeightedMovingAverage). | ||
*/ | ||
private TaskTrackingConfig( | ||
boolean trackExecutionTime, | ||
boolean trackOngoingTasks, | ||
boolean trackMaxQueueLatency, | ||
double executionTimeEWMAAlpha | ||
) { | ||
this.trackExecutionTime = trackExecutionTime; | ||
this.trackOngoingTasks = trackOngoingTasks; | ||
this.trackMaxQueueLatency = trackMaxQueueLatency; | ||
this.executionTimeEwmaAlpha = executionTimeEWMAAlpha; | ||
} | ||
|
||
public boolean trackExecutionTime() { | ||
return trackExecutionTime; | ||
} | ||
|
||
public boolean trackOngoingTasks() { | ||
return trackOngoingTasks; | ||
} | ||
|
||
public boolean trackMaxQueueLatency() { | ||
return trackMaxQueueLatency; | ||
} | ||
|
||
public double getExecutionTimeEwmaAlpha() { | ||
return executionTimeEwmaAlpha; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private boolean trackExecutionTime = false; | ||
private boolean trackUtilization = false; | ||
private boolean trackOngoingTasks = false; | ||
private boolean trackMaxQueueLatency = false; | ||
private double ewmaAlpha = DEFAULT_EXECUTION_TIME_EWMA_ALPHA_FOR_TEST; | ||
private Duration utilizationInterval = DEFAULT_UTILIZATION_INTERVAL; | ||
private Duration utilizationSamplingInterval = DEFAULT_UTILIZATION_SAMPLING_INTERVAL; | ||
|
||
public Builder() {} | ||
|
||
public Builder trackExecutionTime(double alpha) { | ||
trackExecutionTime = true; | ||
trackUtilization = true; | ||
ewmaAlpha = alpha; | ||
return this; | ||
} | ||
|
||
public Builder trackUtilization(Duration interval, Duration samplingInterval) { | ||
assert interval.dividedBy(samplingInterval) > 0 : "interval should be same or larger than sampling interval"; | ||
trackUtilization = true; | ||
utilizationInterval = interval; | ||
utilizationSamplingInterval = samplingInterval; | ||
return this; | ||
} | ||
|
||
public Builder trackOngoingTasks() { | ||
trackOngoingTasks = true; | ||
return this; | ||
|
@@ -661,7 +662,15 @@ public Builder trackMaxQueueLatency() { | |
} | ||
|
||
public TaskTrackingConfig build() { | ||
return new TaskTrackingConfig(trackExecutionTime, trackOngoingTasks, trackMaxQueueLatency, ewmaAlpha); | ||
return new TaskTrackingConfig( | ||
trackExecutionTime, | ||
trackUtilization, | ||
utilizationInterval, | ||
utilizationSamplingInterval, | ||
trackOngoingTasks, | ||
trackMaxQueueLatency, | ||
ewmaAlpha | ||
); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.