use of org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics in project rpcx-benchmark by rpcx-ecosystem.
the class DemoAction method start.
public void start() throws Exception {
final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();
DubboBenchmark.BenchmarkMessage msg = prepareArgs();
final byte[] msgBytes = msg.toByteArray();
final CountDownLatch latch = new CountDownLatch(this.count);
ExecutorService es = Executors.newFixedThreadPool(threads);
final AtomicInteger trans = new AtomicInteger(0);
final AtomicInteger transOK = new AtomicInteger(0);
long start = System.currentTimeMillis();
for (int i = 0; i < this.count; i++) {
es.submit(new Runnable() {
@Override
public void run() {
try {
long t = System.currentTimeMillis();
DubboBenchmark.BenchmarkMessage m = testSay(msgBytes);
t = System.currentTimeMillis() - t;
stats.addValue(t);
trans.incrementAndGet();
if (m != null && m.getField1().equals("OK")) {
transOK.incrementAndGet();
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
latch.countDown();
}
}
});
}
latch.await();
start = System.currentTimeMillis() - start;
System.out.printf("sent requests : %d\n", this.count);
System.out.printf("received requests : %d\n", trans.get());
System.out.printf("received requests_OK : %d\n", transOK.get());
System.out.printf("throughput (TPS) : %d\n", this.count * 1000 / start);
System.out.printf("mean: %f\n", stats.getMean());
System.out.printf("median: %f\n", stats.getPercentile(50));
System.out.printf("max: %f\n", stats.getMax());
System.out.printf("min: %f\n", stats.getMin());
System.out.printf("99P: %f\n", stats.getPercentile(90));
}
use of org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics in project atomix by atomix.
the class AbstractClientConnection method addReplyTime.
/**
* Adds a reply time to the history.
*
* @param type the message type
* @param replyTime the reply time to add to the history
*/
private void addReplyTime(String type, long replyTime) {
DescriptiveStatistics samples = replySamples.get(type);
if (samples == null) {
samples = replySamples.computeIfAbsent(type, t -> new SynchronizedDescriptiveStatistics(WINDOW_SIZE));
}
samples.addValue(replyTime);
}
use of org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics in project rpcx-benchmark by rpcx-ecosystem.
the class AppClient method main.
public static void main(String[] args) throws Exception {
String host = args[0];
final int threads = Integer.parseInt(args[1]);
int n = Integer.parseInt(args[2]);
BenchmarkMessage msg = prepareArgs();
Greeter.Client[] client = createClients(host, threads, msg);
final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();
ExecutorService es = Executors.newFixedThreadPool(threads);
final AtomicInteger trans = new AtomicInteger(0);
final AtomicInteger transOK = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(n);
// count per client
final int count = n / threads;
// warmup
for (int i = 0; i < threads; i++) {
client[i].say(msg);
}
long start = System.currentTimeMillis();
for (int i = 0; i < threads; i++) {
final int k = i;
es.submit(() -> {
for (int j = 0; j < count; j++) {
try {
long t = System.currentTimeMillis();
BenchmarkMessage m = client[k].say(msg);
t = System.currentTimeMillis() - t;
stats.addValue(t);
trans.incrementAndGet();
if (m != null && m.getField1().equals("OK")) {
transOK.incrementAndGet();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
latch.countDown();
}
}
});
}
latch.await();
start = System.currentTimeMillis() - start;
System.out.printf("sent requests : %d\n", n);
System.out.printf("received requests : %d\n", trans.get());
System.out.printf("received requests_OK : %d\n", transOK.get());
System.out.printf("throughput (TPS) : %d\n", n * 1000 / start);
System.out.printf("mean: %f\n", stats.getMean());
System.out.printf("median: %f\n", stats.getPercentile(50));
System.out.printf("max: %f\n", stats.getMax());
System.out.printf("min: %f\n", stats.getMin());
System.out.printf("99P: %f\n", stats.getPercentile(99.9));
}
Aggregations