From 55ffbd77d2447dda1ac96f34d7d38b1e9b684bdb Mon Sep 17 00:00:00 2001 From: WuYunlong Date: Mon, 22 Apr 2024 16:50:09 +0800 Subject: [PATCH] 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 Co-authored-by: ZhangJian He --- .../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 3c4294e7217..9eeae28f1a3 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 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; } /**