Skip to content

Commit

Permalink
fix wrong implementation for percentile in bookkeeper-benchmark (ap…
Browse files Browse the repository at this point in the history
…ache#3864)

According to `https://stackoverflow.com/questions/12808934/what-is-p99-latency`,
the implementation for `percentile` in bookkeeper-benchmark is wrong.

Signed-off-by: ZhangJian He <shoothzj@gmail.com>
Co-authored-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
2 people authored and Anup Ghatage committed Jul 12, 2024
1 parent 22b6a87 commit 27d9b12
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,9 @@ public void process(WatchedEvent event) {
private static double percentile(long[] latency, int percentile) {
int size = latency.length;
double percent = (double) percentile / 100;
int sampleSize = (int) (size * percent);
long total = 0;
int count = 0;
for (int i = 0; i < sampleSize; i++) {
total += latency[i];
count++;
}
return ((double) total / (double) count) / 1000000.0;
int index = (int) (size * percent);
double lat = index > 0 ? (double) latency[index - 1] / 1000000.0 : 0.0;
return lat;
}

/**
Expand Down

0 comments on commit 27d9b12

Please sign in to comment.