-
Notifications
You must be signed in to change notification settings - Fork 616
HDDS-9522. Add percentile for ProtocolMessageMetrics #5479
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,13 +22,17 @@ | |||||||||||||||||||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||||||||||||||||||||
| import java.util.concurrent.atomic.AtomicLong; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.MetricsCollector; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.MetricsInfo; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.MetricsSource; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.MetricsTag; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.lib.Interns; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.lib.MetricsRegistry; | ||||||||||||||||||||||
| import org.apache.hadoop.metrics2.lib.MutableQuantiles; | ||||||||||||||||||||||
| import org.apache.hadoop.ozone.OzoneConfigKeys; | ||||||||||||||||||||||
| import org.apache.ratis.util.UncheckedAutoCloseable; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
|
|
@@ -40,32 +44,59 @@ public class ProtocolMessageMetrics<KEY> implements MetricsSource { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final String description; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final MetricsRegistry registry; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final boolean quantileEnable; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final Map<KEY, AtomicLong> counters = | ||||||||||||||||||||||
| new ConcurrentHashMap<>(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final Map<KEY, AtomicLong> elapsedTimes = | ||||||||||||||||||||||
| new ConcurrentHashMap<>(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final Map<KEY, MutableQuantiles[]> quantiles = | ||||||||||||||||||||||
| new ConcurrentHashMap<>(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private final AtomicInteger concurrency = new AtomicInteger(0); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public static <KEY> ProtocolMessageMetrics<KEY> create(String name, | ||||||||||||||||||||||
| String description, KEY[] types) { | ||||||||||||||||||||||
| return new ProtocolMessageMetrics<KEY>(name, description, types); | ||||||||||||||||||||||
| String description, KEY[] types, ConfigurationSource conf) { | ||||||||||||||||||||||
| return new ProtocolMessageMetrics<KEY>(name, description, types, conf); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public ProtocolMessageMetrics(String name, String description, | ||||||||||||||||||||||
| KEY[] values) { | ||||||||||||||||||||||
| KEY[] values, ConfigurationSource conf) { | ||||||||||||||||||||||
| this.name = name; | ||||||||||||||||||||||
| this.description = description; | ||||||||||||||||||||||
| registry = new MetricsRegistry(name + "MessageMetrics"); | ||||||||||||||||||||||
| int[] intervals = conf.getInts( | ||||||||||||||||||||||
| OzoneConfigKeys.OZONE_PROTOCOL_MESSAGE_METRICS_PERCENTILES_INTERVALS); | ||||||||||||||||||||||
| quantileEnable = (intervals.length > 0); | ||||||||||||||||||||||
| for (KEY value : values) { | ||||||||||||||||||||||
| counters.put(value, new AtomicLong(0)); | ||||||||||||||||||||||
| elapsedTimes.put(value, new AtomicLong(0)); | ||||||||||||||||||||||
| if (quantileEnable) { | ||||||||||||||||||||||
| MutableQuantiles[] mutableQuantiles = | ||||||||||||||||||||||
| new MutableQuantiles[intervals.length]; | ||||||||||||||||||||||
| quantiles.put(value, mutableQuantiles); | ||||||||||||||||||||||
| for (int i = 0; i < intervals.length; i++) { | ||||||||||||||||||||||
| mutableQuantiles[i] = registry.newQuantiles( | ||||||||||||||||||||||
| value.toString() + "RpcTime" + intervals[i] + "s", | ||||||||||||||||||||||
| value.toString() + "rpc time in milli second", | ||||||||||||||||||||||
| "ops", "latency", intervals[i]); | ||||||||||||||||||||||
|
Contributor
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. It would be better to clarify the unit of time in the name of the Metrics, such as Use
Contributor
Author
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. Now the name of the Metric will be like “InfoVolumeRpcTime127s90thPercentileLatency” and the unit of time is including in it as "s". It will be appreciated if you could tell me how to let it more suitable. How about "InfoVolumeRpcTime127latencySeconds90thPercentileLatency"? @xichen01
Contributor
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 think that
Contributor
Author
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.
Thank you for your feedback! I appreciate your clarification on the suggestion you provided. I now understand it better, and I will proceed to make the necessary modifications according to your advice.
Contributor
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. Sorry for not expressing it clearly, I think we can remove the type from the Metrics name when we move it to the tag, so the name can be
Suggested change
The Metrics name will be like this |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public void increment(KEY key, long duration) { | ||||||||||||||||||||||
| counters.get(key).incrementAndGet(); | ||||||||||||||||||||||
| elapsedTimes.get(key).addAndGet(duration); | ||||||||||||||||||||||
| if (quantileEnable) { | ||||||||||||||||||||||
| for (MutableQuantiles q : quantiles.get(key)) { | ||||||||||||||||||||||
|
xBis7 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| q.add(duration); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public UncheckedAutoCloseable measure(KEY key) { | ||||||||||||||||||||||
|
|
@@ -74,7 +105,13 @@ public UncheckedAutoCloseable measure(KEY key) { | |||||||||||||||||||||
| return () -> { | ||||||||||||||||||||||
| concurrency.decrementAndGet(); | ||||||||||||||||||||||
| counters.get(key).incrementAndGet(); | ||||||||||||||||||||||
| elapsedTimes.get(key).addAndGet(System.currentTimeMillis() - startTime); | ||||||||||||||||||||||
| long delta = System.currentTimeMillis() - startTime; | ||||||||||||||||||||||
| elapsedTimes.get(key).addAndGet(delta); | ||||||||||||||||||||||
| if (quantileEnable) { | ||||||||||||||||||||||
| for (MutableQuantiles q : quantiles.get(key)) { | ||||||||||||||||||||||
| q.add(delta); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -89,6 +126,7 @@ public void unregister() { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Override | ||||||||||||||||||||||
| public void getMetrics(MetricsCollector collector, boolean all) { | ||||||||||||||||||||||
| registry.snapshot(collector.addRecord(registry.info()), all); | ||||||||||||||||||||||
|
xBis7 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| counters.forEach((key, value) -> { | ||||||||||||||||||||||
| MetricsRecordBuilder builder = | ||||||||||||||||||||||
| collector.addRecord(name); | ||||||||||||||||||||||
|
|
@@ -129,4 +167,8 @@ public String description() { | |||||||||||||||||||||
| return description; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public boolean isQuantileEnable() { | ||||||||||||||||||||||
|
xBis7 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| return quantileEnable; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.