This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 55ffbd77d2 fix wrong implementation for `percentile` in 
bookkeeper-benchmark (#3864)
55ffbd77d2 is described below

commit 55ffbd77d2447dda1ac96f34d7d38b1e9b684bdb
Author: WuYunlong <[email protected]>
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 <[email protected]>
    Co-authored-by: ZhangJian He <[email protected]>
---
 .../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;
     }
 
     /**

Reply via email to