-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16949 Introduce inverse quantiles for metrics where higher numer… #5486
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
056a473
a66f26a
6bca0d1
a30980e
8888f8c
62a29be
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 |
|---|---|---|
|
|
@@ -71,9 +71,11 @@ public class SampleQuantiles implements QuantileEstimator { | |
| * Array of Quantiles that we care about, along with desired error. | ||
| */ | ||
| private final Quantile quantiles[]; | ||
| private boolean inverseQuantiles; | ||
|
|
||
| public SampleQuantiles(Quantile[] quantiles) { | ||
| public SampleQuantiles(Quantile[] quantiles, boolean inverseQuantiles) { | ||
| this.quantiles = quantiles; | ||
| this. inverseQuantiles = inverseQuantiles; | ||
| this.samples = new LinkedList<SampleItem>(); | ||
| } | ||
|
|
||
|
|
@@ -200,7 +202,7 @@ private void compress() { | |
| /** | ||
| * Get the estimated value at the specified quantile. | ||
| * | ||
| * @param quantile Queried quantile, e.g. 0.50 or 0.99. | ||
| * @param quantile Queried quantile, e.g. 0.01, 0.50 or 0.99. | ||
| * @return Estimated value at that quantile. | ||
| */ | ||
| private long query(double quantile) { | ||
|
|
@@ -243,7 +245,12 @@ synchronized public Map<Quantile, Long> snapshot() { | |
|
|
||
| Map<Quantile, Long> values = new TreeMap<Quantile, Long>(); | ||
| for (int i = 0; i < quantiles.length; i++) { | ||
| values.put(quantiles[i], query(quantiles[i].quantile)); | ||
| /* eg : effectiveQuantile for 0.99 with inverseQuantiles will be 0.01. | ||
|
||
| For inverse quantiles higher numeric value is better and hence we want | ||
| to query from the opposite end of the sorted sample | ||
| */ | ||
| double effectiveQuantile = inverseQuantiles ? 1 - quantiles[i].quantile : quantiles[i].quantile; | ||
|
||
| values.put(quantiles[i], query(effectiveQuantile)); | ||
|
||
| } | ||
|
|
||
| return values; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ public class TestSampleQuantiles { | |
|
|
||
| @Before | ||
| public void init() { | ||
| estimator = new SampleQuantiles(quantiles); | ||
| estimator = new SampleQuantiles(quantiles, false); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -118,4 +118,36 @@ public void testQuantileError() throws IOException { | |
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testInverseQuantiles() { | ||
|
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. nit: can you just add a description of what the test is doing |
||
| SampleQuantiles estimatorWithInverseQuantiles = new SampleQuantiles(quantiles, true); | ||
| final int count = 100000; | ||
| Random r = new Random(0xDEADDEAD); | ||
| Long[] values = new Long[count]; | ||
| for (int i = 0; i < count; i++) { | ||
| values[i] = (long) (i + 1); | ||
| } | ||
| // Do 10 shuffle/insert/check cycles | ||
| for (int i = 0; i < 10; i++) { | ||
| System.out.println("Starting run " + i); | ||
| Collections.shuffle(Arrays.asList(values), r); | ||
| estimatorWithInverseQuantiles.clear(); | ||
| for (int j = 0; j < count; j++) { | ||
| estimatorWithInverseQuantiles.insert(values[j]); | ||
| } | ||
| Map<Quantile, Long> snapshot; | ||
| snapshot = estimatorWithInverseQuantiles.snapshot(); | ||
| for (Quantile q : quantiles) { | ||
| long actual = (long) ((1 - q.quantile) * count); | ||
| long error = (long) ((0.1 - q.error) * count); | ||
| long estimate = snapshot.get(q); | ||
| System.out | ||
| .println(String.format("For quantile %f Expected %d with error %d, estimated %d", | ||
| q.quantile, actual, error, estimate)); | ||
| assertThat(estimate <= actual + error).isTrue(); | ||
| assertThat(estimate >= actual - error).isTrue(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
private final booleanYou will also need to set it in the constructor.