-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Publish queue latency metrics from tracked thread pools #120488
Open
nicktindall
wants to merge
29
commits into
elastic:main
Choose a base branch
from
nicktindall:ES-10531_add_thread_pool_queue_latency_metric
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.
+404
−196
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9918299
Publish queue latency metrics from tracked thread pools
nicktindall b1d8df4
Merge remote-tracking branch 'origin/main' into ES-10531_add_thread_p…
nicktindall dfef676
Fix metric name
nicktindall 2ceb965
Temporary hack to fix metric name
nicktindall dbed27f
Propose solution to composite thread-pool names
nicktindall c04f2ea
Merge remote-tracking branch 'origin/main' into ES-10531_add_thread_p…
nicktindall c95f625
Fix fixed thread pool names
nicktindall f850bc9
Merge remote-tracking branch 'origin/main' into ES-10531_add_thread_p…
nicktindall 1b450f0
Merge branch 'main' into ES-10531_add_thread_pool_queue_latency_metric
nicktindall e7f5bb6
POC using HandlingTimeTracker to track queue latency
nicktindall d269195
Merge branch 'main' into ES-10531_add_thread_pool_queue_latency_metric
nicktindall 80b8b3f
Tidy
nicktindall 9811299
Merge branch 'main' into ES-10531_add_thread_pool_queue_latency_metric
nicktindall 598d0a8
Fix metric name
nicktindall 4153d27
Generalise HandlingTimeTracker
nicktindall d4b0818
Merge remote-tracking branch 'origin/main' into ES-10531_add_thread_p…
nicktindall 3e3d9fc
Tidy and fix document/test
nicktindall be4b96c
Restore field name
nicktindall 8a313ab
Update docs/changelog/120488.yaml
nicktindall 8fa7dc6
Fix changelog area value
nicktindall 2c36b97
Update server/src/main/java/org/elasticsearch/common/metrics/Exponent…
nicktindall 420739e
Setup metrics separately to constructor
nicktindall 3208423
Remove unnecessary change
nicktindall 9dd0457
Merge remote-tracking branch 'origin/main' into ES-10531_add_thread_p…
nicktindall 516a4a9
Merge branch 'main' into ES-10531_add_thread_pool_queue_latency_metric
nicktindall d6e44ed
Add 99th percentile
nicktindall dfbd9ac
Merge branch 'main' into ES-10531_add_thread_pool_queue_latency_metric
nicktindall 2b294bd
Record queue latency metrics in beforeExecute
nicktindall 9e227ed
Handle p100 percentile when last bucket is populated
nicktindall 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
This file contains 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: 120488 | ||
summary: Publish queue latency metrics from tracked thread pools | ||
area: "Infra/Metrics" | ||
type: enhancement | ||
issues: [] |
106 changes: 106 additions & 0 deletions
106
server/src/main/java/org/elasticsearch/common/metrics/ExponentialBucketHistogram.java
This file contains 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,106 @@ | ||
/* | ||
* 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.common.metrics; | ||
|
||
import java.util.Arrays; | ||
import java.util.concurrent.atomic.LongAdder; | ||
|
||
/** | ||
* A histogram with a fixed number of buckets of exponentially increasing width. | ||
* <p> | ||
* The bucket boundaries are defined by increasing powers of two, e.g. | ||
* <code> | ||
* (-∞, 1), [1, 2), [2, 4), [4, 8), ..., [2^({@link #BUCKET_COUNT}-2), ∞) | ||
* </code> | ||
* There are {@link #BUCKET_COUNT} buckets. | ||
*/ | ||
public class ExponentialBucketHistogram { | ||
|
||
public static int[] getBucketUpperBounds() { | ||
int[] bounds = new int[17]; | ||
for (int i = 0; i < bounds.length; i++) { | ||
bounds[i] = 1 << i; | ||
} | ||
return bounds; | ||
} | ||
|
||
private static int getBucket(long observedValue) { | ||
if (observedValue <= 0) { | ||
return 0; | ||
} else if (LAST_BUCKET_LOWER_BOUND <= observedValue) { | ||
return BUCKET_COUNT - 1; | ||
} else { | ||
return Long.SIZE - Long.numberOfLeadingZeros(observedValue); | ||
} | ||
} | ||
|
||
public static final int BUCKET_COUNT = getBucketUpperBounds().length + 1; | ||
|
||
private static final long LAST_BUCKET_LOWER_BOUND = getBucketUpperBounds()[BUCKET_COUNT - 2]; | ||
|
||
private final LongAdder[] buckets; | ||
|
||
public ExponentialBucketHistogram() { | ||
buckets = new LongAdder[BUCKET_COUNT]; | ||
for (int i = 0; i < BUCKET_COUNT; i++) { | ||
buckets[i] = new LongAdder(); | ||
} | ||
} | ||
|
||
public void addObservation(long observedValue) { | ||
buckets[getBucket(observedValue)].increment(); | ||
} | ||
|
||
/** | ||
* @return An array of frequencies of handling times in buckets with upper bounds as returned by {@link #getBucketUpperBounds()}, plus | ||
* an extra bucket for handling times longer than the longest upper bound. | ||
*/ | ||
public long[] getHistogram() { | ||
final long[] histogram = new long[BUCKET_COUNT]; | ||
for (int i = 0; i < BUCKET_COUNT; i++) { | ||
histogram[i] = buckets[i].longValue(); | ||
} | ||
return histogram; | ||
} | ||
|
||
/** | ||
* Calculate the Nth percentile value | ||
* | ||
* @param percentile The percentile as a fraction (in [0, 1.0]) | ||
* @return A value greater than the specified fraction of values in the histogram | ||
*/ | ||
public long getPercentile(float percentile) { | ||
assert percentile >= 0 && percentile <= 1; | ||
final long[] snapshot = getHistogram(); | ||
final long totalCount = Arrays.stream(snapshot).sum(); | ||
long percentileIndex = (long) Math.ceil(totalCount * percentile); | ||
for (int i = 0; i < BUCKET_COUNT; i++) { | ||
percentileIndex -= snapshot[i]; | ||
if (percentileIndex <= 0) { | ||
if (i == snapshot.length - 1) { | ||
return Long.MAX_VALUE; | ||
} else { | ||
return getBucketUpperBounds()[i]; | ||
} | ||
} | ||
} | ||
assert false : "We shouldn't ever get here"; | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
/** | ||
* Clear all values in the histogram (non-atomic) | ||
*/ | ||
public void clear() { | ||
for (int i = 0; i < BUCKET_COUNT; i++) { | ||
buckets[i].reset(); | ||
} | ||
} | ||
} |
66 changes: 0 additions & 66 deletions
66
server/src/main/java/org/elasticsearch/common/network/HandlingTimeTracker.java
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if rather than publishing a time-series-per-percentile (using
percentile
attribute) we should publish a metric-per-percentile.The metric makes no sense if you don't filter by a percentile label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it easier to plot different percentiles on the same graph with labels (and group by) compared to two different time series?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that makes a difference, but I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just having a look at Kibana just now, it would be much easier to plot as a single metric grouped-by the percentiles. As separate metrics we'd need to add them as distinct time-series.