You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by sh...@apache.org on 2024/05/25 06:01:40 UTC
(bookkeeper) 01/05: fix wrong implementation for `percentile` in bookkeeper-benchmark (#3864)
This is an automated email from the ASF dual-hosted git repository.
shoothzj pushed a commit to branch branch-4.17
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit 2292ce2fc60d96d86526ea3377353dac72b33730
Author: WuYunlong <xz...@126.com>
AuthorDate: Mon Apr 22 16:50:09 2024 +0800
fix wrong implementation for `percentile` in bookkeeper-benchmark (#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 <sh...@gmail.com>
Co-authored-by: ZhangJian He <sh...@gmail.com>
(cherry picked from commit 55ffbd77d2447dda1ac96f34d7d38b1e9b684bdb)
---
.../apache/bookkeeper/benchmark/BenchThroughputLatency.java | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/bookkeeper-benchmark/src/main/java/org/apache/bookkeeper/benchmark/BenchThroughputLatency.java b/bookkeeper-benchmark/src/main/java/org/apache/bookkeeper/benchmark/BenchThroughputLatency.java
index 3c4294e721..9eeae28f1a 100644
--- a/bookkeeper-benchmark/src/main/java/org/apache/bookkeeper/benchmark/BenchThroughputLatency.java
+++ b/bookkeeper-benchmark/src/main/java/org/apache/bookkeeper/benchmark/BenchThroughputLatency.java
@@ -431,14 +431,9 @@ public class BenchThroughputLatency implements AddCallback, Runnable {
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;
}
/**