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

lhotari pushed a commit to branch branch-4.15
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit 827a62ee8295b88c2a51ba6638bfe09857915623
Author: WuYunlong <xzs...@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 <shoot...@gmail.com>
    Co-authored-by: ZhangJian He <shoot...@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 08c08e57cc..ffe1ee42b2 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
@@ -420,14 +420,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