-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ravindra Dingankar
committed
Mar 16, 2023
1 parent
056a473
commit efc6016
Showing
6 changed files
with
63 additions
and
21 deletions.
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
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
44 changes: 44 additions & 0 deletions
44
...project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/InverseQuantiles.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,44 @@ | ||
package org.apache.hadoop.metrics2.util; | ||
|
||
import org.apache.hadoop.util.Preconditions; | ||
import java.util.ListIterator; | ||
|
||
public class InverseQuantiles extends SampleQuantiles{ | ||
|
||
public InverseQuantiles(Quantile[] quantiles) { | ||
super(quantiles); | ||
} | ||
|
||
|
||
/** | ||
* Get the estimated value at the inverse of the specified quantile. | ||
* Eg: return the value at (1 - 0.99)*count position for quantile 0.99. | ||
* When count is 100, quantile 0.99 is desired to return the value at the 1st position | ||
* | ||
* @param quantile Queried quantile, e.g. 0.50 or 0.99. | ||
* @return Estimated value at the inverse position of that quantile. | ||
*/ | ||
long query(double quantile) { | ||
Preconditions.checkState(!samples.isEmpty(), "no data in estimator"); | ||
|
||
int rankMin = 0; | ||
int desired = (int) ((1 - quantile) * count); | ||
|
||
ListIterator<SampleItem> it = samples.listIterator(); | ||
SampleItem prev; | ||
SampleItem cur = it.next(); | ||
for (int i = 1; i < samples.size(); i++) { | ||
prev = cur; | ||
cur = it.next(); | ||
|
||
rankMin += prev.g; | ||
|
||
if (rankMin + cur.g + cur.delta > desired + (allowableError(i) / 2)) { | ||
return prev.value; | ||
} | ||
} | ||
|
||
// edge case of wanting max value | ||
return samples.get(samples.size() - 1).value; | ||
} | ||
} |
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