Search in sources :

Example 1 with SynchronizedDescriptiveStatistics

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));
}
Also used : SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) DubboBenchmark(org.apache.dubbo.bench.DubboBenchmark) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with SynchronizedDescriptiveStatistics

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);
}
Also used : SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) Logger(org.slf4j.Logger) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) Duration(java.time.Duration) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectException(java.net.ConnectException) MessagingException(io.atomix.cluster.messaging.MessagingException) SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics)

Example 3 with SynchronizedDescriptiveStatistics

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));
}
Also used : SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) SynchronizedDescriptiveStatistics(org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)3 SynchronizedDescriptiveStatistics (org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Maps (com.google.common.collect.Maps)1 MessagingException (io.atomix.cluster.messaging.MessagingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 Duration (java.time.Duration)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DubboBenchmark (org.apache.dubbo.bench.DubboBenchmark)1 TException (org.apache.thrift.TException)1