Search in sources :

Example 1 with AverageMinMax

use of org.jgroups.util.AverageMinMax in project JGroups by belaban.

the class AverageTest method testMerge.

public void testMerge() {
    AverageMinMax avg1 = new AverageMinMax(), avg2 = new AverageMinMax();
    IntStream.rangeClosed(1, 1000).forEach(i -> avg1.add(1));
    IntStream.rangeClosed(1, 10000).forEach(i -> avg2.add(2));
    System.out.printf("avg1: %s, avg2: %s\n", avg1, avg2);
    avg1.merge(avg2);
    System.out.printf("merged avg1: %s\n", avg1);
    assert avg1.count() == 5500;
    double diff = Math.abs(avg1.getAverage() - 1.90);
    assert diff < 0.01;
    assert avg1.min() == 1;
    assert avg1.max() == 2;
}
Also used : AverageMinMax(org.jgroups.util.AverageMinMax)

Example 2 with AverageMinMax

use of org.jgroups.util.AverageMinMax in project JGroups by belaban.

the class ProgrammaticUPerf2 method startBenchmark.

/**
 * Kicks off the benchmark on all cluster nodes
 */
protected void startBenchmark() {
    RspList<Results> responses = null;
    try {
        RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0);
        options.flags(Message.Flag.OOB, Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
        responses = disp.callRemoteMethods(null, new CustomCall(START), options);
    } catch (Throwable t) {
        System.err.println("starting the benchmark failed: " + t);
        return;
    }
    long total_reqs = 0;
    long total_time = 0;
    AverageMinMax avg_gets = null, avg_puts = null;
    System.out.println("\n======================= Results: ===========================");
    for (Map.Entry<Address, Rsp<Results>> entry : responses.entrySet()) {
        Address mbr = entry.getKey();
        Rsp<Results> rsp = entry.getValue();
        Results result = rsp.getValue();
        if (result != null) {
            total_reqs += result.num_gets + result.num_puts;
            total_time += result.total_time;
            if (avg_gets == null)
                avg_gets = result.avg_gets;
            else
                avg_gets.merge(result.avg_gets);
            if (avg_puts == null)
                avg_puts = result.avg_puts;
            else
                avg_puts.merge(result.avg_puts);
        }
        System.out.println(mbr + ": " + result);
    }
    double total_reqs_sec = total_reqs / (total_time / 1000.0);
    double throughput = total_reqs_sec * BUFFER.length;
    System.out.println("\n");
    System.out.println(Util.bold(String.format("Throughput: %,.2f reqs/sec/node (%s/sec)\n" + "Roundtrip:  gets %s, puts %s\n", total_reqs_sec, Util.printBytes(throughput), print(avg_gets, print_details), print(avg_puts, print_details))));
    System.out.println("\n\n");
}
Also used : InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) RequestOptions(org.jgroups.blocks.RequestOptions) Rsp(org.jgroups.util.Rsp) AverageMinMax(org.jgroups.util.AverageMinMax)

Example 3 with AverageMinMax

use of org.jgroups.util.AverageMinMax in project JGroups by belaban.

the class ProgrammaticUPerf2 method startTest.

// =================================== callbacks ======================================
public Results startTest() throws Exception {
    BUFFER = new byte[msg_size];
    System.out.printf("running for %d seconds\n", time);
    final CountDownLatch latch = new CountDownLatch(1);
    num_reads.reset();
    num_writes.reset();
    Invoker[] invokers = new Invoker[num_threads];
    for (int i = 0; i < invokers.length; i++) {
        invokers[i] = new Invoker(members, latch);
        // waits on latch
        invokers[i].start();
    }
    long start = System.currentTimeMillis();
    latch.countDown();
    long interval = (long) ((time * 1000.0) / 10.0);
    for (int i = 1; i <= 10; i++) {
        Util.sleep(interval);
        System.out.printf("%d: %s\n", i, printAverage(start));
    }
    for (Invoker invoker : invokers) invoker.cancel();
    for (Invoker invoker : invokers) invoker.join();
    long total_time = System.currentTimeMillis() - start;
    System.out.println();
    AverageMinMax avg_gets = null, avg_puts = null;
    for (Invoker invoker : invokers) {
        if (print_invokers)
            System.out.printf("invoker %s: gets %s puts %s\n", invoker.getId(), print(invoker.avgGets(), print_details), print(invoker.avgPuts(), print_details));
        if (avg_gets == null)
            avg_gets = invoker.avgGets();
        else
            avg_gets.merge(invoker.avgGets());
        if (avg_puts == null)
            avg_puts = invoker.avgPuts();
        else
            avg_puts.merge(invoker.avgPuts());
    }
    if (print_invokers)
        System.out.printf("\navg over all invokers: gets %s puts %s\n", print(avg_gets, print_details), print(avg_puts, print_details));
    System.out.printf("\ndone (in %s ms)\n", total_time);
    return new Results((int) num_reads.sum(), (int) num_writes.sum(), total_time, avg_gets, avg_puts);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AverageMinMax(org.jgroups.util.AverageMinMax)

Example 4 with AverageMinMax

use of org.jgroups.util.AverageMinMax in project JGroups by belaban.

the class RoundTrip method sendRequests.

protected void sendRequests() throws Exception {
    List mbrs = tp.clusterMembers();
    if (mbrs != null && mbrs.size() != 2) {
        System.err.printf("Cluster must have exactly 2 members: %s\n", mbrs);
        return;
    }
    rsp_latency.clear();
    Object target = mbrs != null ? Util.pickNext(mbrs, tp.localAddress()) : null;
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger sent_msgs = new AtomicInteger(0);
    senders = new Sender[num_senders];
    for (int i = 0; i < num_senders; i++) {
        senders[i] = new Sender((short) i, latch, sent_msgs, target);
        senders[i].start();
    }
    long start = time(use_ms);
    // start all sender threads
    latch.countDown();
    for (Sender sender : senders) sender.join();
    long total_time = time(use_ms) - start;
    byte[] done_buf = new byte[PAYLOAD];
    done_buf[0] = DONE;
    tp.send(target, done_buf, 0, done_buf.length);
    double divisor = use_ms ? 1_000.0 : 1_000_000.0;
    double msgs_sec = num_msgs / (total_time / divisor);
    AverageMinMax avg = null;
    if (details)
        System.out.println("");
    for (Sender sender : senders) {
        if (details)
            System.out.printf("%d: %s\n", sender.id, print(sender.rtt));
        if (avg == null)
            avg = sender.rtt;
        else
            avg.merge(sender.rtt);
    }
    System.out.printf(Util.bold("\n\nreqs/sec    = %.2f" + "\nround-trip  = min/avg/max: %d / %.2f / %d %s" + "\nrsp-latency = min/avg/max: %d / %.2f / %d %s\n\n"), msgs_sec, avg.min(), avg.average(), avg.max(), unit(), rsp_latency.min(), rsp_latency.average(), rsp_latency.max(), unit());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) AverageMinMax(org.jgroups.util.AverageMinMax)

Example 5 with AverageMinMax

use of org.jgroups.util.AverageMinMax in project JGroups by belaban.

the class RoundTripRpc method invokeRequests.

protected void invokeRequests() throws Exception {
    View view = channel.getView();
    if (view.size() != 2) {
        System.err.printf("Cluster must have exactly 2 members: %s\n", view);
        return;
    }
    Address target = Util.pickNext(view.getMembers(), channel.getAddress());
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger sent_msgs = new AtomicInteger(0);
    invokers = new Invoker[num_senders];
    for (int i = 0; i < num_senders; i++) {
        invokers[i] = new Invoker((short) i, latch, sent_msgs, target);
        invokers[i].start();
    }
    long start = System.nanoTime();
    // start all sender threads
    latch.countDown();
    for (Invoker invoker : invokers) invoker.join();
    long total_time = System.nanoTime() - start;
    double msgs_sec = num_msgs / (total_time / 1_000_000_000.0);
    AverageMinMax avg = null;
    if (details)
        System.out.println("");
    for (Invoker invoker : invokers) {
        if (details)
            System.out.printf("%d: %s\n", invoker.id, print(invoker.avg));
        if (avg == null)
            avg = invoker.avg;
        else
            avg.merge(invoker.avg);
    }
    System.out.printf(Util.bold("\n\nreqs/sec = %.2f, " + "round-trip = min/avg/max: %.2f / %.2f / %.2f us\n\n"), msgs_sec, avg.min() / 1000.0, avg.average() / 1000.0, avg.max() / 1000.0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) AverageMinMax(org.jgroups.util.AverageMinMax)

Aggregations

AverageMinMax (org.jgroups.util.AverageMinMax)8 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 BytesMessage (org.jgroups.BytesMessage)1 Message (org.jgroups.Message)1 RequestOptions (org.jgroups.blocks.RequestOptions)1 Rsp (org.jgroups.util.Rsp)1