Skip to content

Commit

Permalink
added percentiles
Browse files Browse the repository at this point in the history
  • Loading branch information
breed committed Oct 2, 2011
1 parent e8e762c commit e8c2fec
Showing 1 changed file with 38 additions and 0 deletions.
@@ -1,6 +1,12 @@
package org.apache.bookkeeper.benchmark;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -80,9 +86,12 @@ private int getRandomLedger() {
return lastLedger;
}

long latencies[] = new long[1000000];
int latencyIndex = -1;
int sendLimit = Integer.MAX_VALUE;
public void setSendLimit(int sendLimit) {
this.sendLimit = sendLimit;
latencies = new long[sendLimit];
}

public void run() {
Expand Down Expand Up @@ -165,6 +174,11 @@ public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
int c = -1;
synchronized(this) {
runningAverageCounter++;
latencies[(int)entryId] = newTime;
if (latencyIndex >= entryId) {
LOG.error("On entry " + entryId + " ledgerIndex = " + latencyIndex);
}
latencyIndex = (int)entryId;
totalTime += newTime;
completions++;
tt = totalTime;
Expand Down Expand Up @@ -277,9 +291,33 @@ public static void main(String[] args)
double tp = (double)cc/(double)runningTime;
System.out.println(cc + " completions in " + totalTime + " seconds: " + tp + " ops/sec");
System.out.println("Average latency: " + ((double)tt /(double)rac)/1000000.0);
ArrayList<Long> latency = new ArrayList<Long>();
for(int i = 0; i < ttl.latencyIndex; i++) {
latency.add(ttl.latencies[i]);
}
Collections.sort(latency);
System.out.println("99th percentile latency: " + percentile(latency, 99));
System.out.println("95th percentile latency: " + percentile(latency, 95));
OutputStream fos = new BufferedOutputStream(new FileOutputStream("latencyDump.dat"));

for(Long l: latency) {
fos.write((Long.toString(l)+"\n").getBytes());
}
fos.flush();
Runtime.getRuntime().halt(0);
}

private static double percentile(ArrayList<Long> latency, int percentile) {
int size = latency.size();
int sampleSize = (size * percentile) / 100;
int skip = size - sampleSize;
long total = 0;
for(int i = skip; i < size; i++) {
total += latency.get(i);
}
return (double)total/(double)sampleSize;
}

private static long warmUp(String servers, int paceInNanos, byte[] data,
int ledgers, int ensemble, int qSize, int throttle)
throws KeeperException, IOException, InterruptedException {
Expand Down

0 comments on commit e8c2fec

Please sign in to comment.