Search in sources :

Example 6 with AverageMinMax

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

the class BundlerStressTest method sendMessages.

protected void sendMessages() throws Exception {
    Message[] msgs = generateMessages(num_msgs);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicInteger index = new AtomicInteger(0);
    Sender[] senders = new Sender[num_senders];
    for (int i = 0; i < senders.length; i++) {
        senders[i] = new Sender(latch, msgs, index);
        senders[i].start();
    }
    long start = Util.micros();
    // starts all sender threads
    latch.countDown();
    for (Sender sender : senders) sender.join();
    // wait until the bundler has no pending msgs left
    long park_time = 1;
    for (int i = 0; i < 1_000_000; i++) {
        int pending_msgs = bundler.size();
        if (pending_msgs == 0)
            break;
        LockSupport.parkNanos(park_time);
        if (i % 10000 == 0) {
            // 1 ms max park time
            park_time = Math.min(park_time * 2, 1_000_000);
        }
    }
    if (bundler.size() > 0)
        throw new Exception(String.format("bundler still has %d pending messages", bundler.size()));
    long time_us = Util.micros() - start;
    AverageMinMax send_avg = null;
    for (Sender sender : senders) {
        if (details)
            System.out.printf("[%d] count=%d, send-time = %s\n", sender.getId(), sender.send.count(), sender.send);
        if (send_avg == null)
            send_avg = sender.send;
        else
            send_avg.merge(sender.send);
    }
    double msgs_sec = num_msgs / (time_us / 1_000.0);
    System.out.printf(Util.bold("\n\nreqs/ms    = %.2f (time: %d us)" + "\nsend-time  = min/avg/max: %d / %.2f / %d ns\n"), msgs_sec, time_us, send_avg.min(), send_avg.average(), send_avg.max());
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) AverageMinMax(org.jgroups.util.AverageMinMax)

Example 7 with AverageMinMax

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

the class AverageTest method testMinMax.

public void testMinMax() {
    AverageMinMax avg = new AverageMinMax();
    IntStream.rangeClosed(1, 10).forEach(avg::add);
    double average = IntStream.rangeClosed(1, 10).average().orElse(0.0);
    assert avg.getAverage() == average;
    assert avg.min() == 1;
    assert avg.max() == 10;
}
Also used : AverageMinMax(org.jgroups.util.AverageMinMax)

Example 8 with AverageMinMax

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

the class AverageTest method testMerger2.

public void testMerger2() {
    AverageMinMax avg1 = new AverageMinMax(), avg2 = new AverageMinMax();
    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() == 5000;
    assert avg1.average() == 2.0;
    assert avg1.min() == 2;
    assert avg1.max() == 2;
}
Also used : 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