Search in sources :

Example 1 with Average

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

the class PERF method init.

public void init() throws Exception {
    super.init();
    avg = new Average();
}
Also used : Average(org.jgroups.util.Average)

Example 2 with Average

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

the class AverageTest method testOverflow.

public void testOverflow() {
    long start = Long.MAX_VALUE / 500;
    Average avg = new Average();
    for (int i = 0; i < 1000; i++) avg.add(start++);
    long cnt = avg.getCount();
    System.out.printf("cnt=%d, avg=%.2f\n", cnt, avg.getAverage());
    // was reset at i=500
    assert cnt == 500;
}
Also used : Average(org.jgroups.util.Average)

Example 3 with Average

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

the class AverageTest method testAverage.

public void testAverage() {
    long[] numbers = new long[1000];
    long total = 0;
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = Util.random(10000);
        total += numbers[i];
    }
    double expected_avg = total / 1000.0;
    Average a = new Average();
    for (long num : numbers) a.add(num);
    double avg = a.getAverage();
    expected_avg = Math.floor(expected_avg);
    avg = Math.floor(avg);
    assert avg == expected_avg;
}
Also used : Average(org.jgroups.util.Average)

Example 4 with Average

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

the class RpcDispatcherSpeedTest method invokeRpcs.

protected void invokeRpcs() throws Exception {
    Average avg = new Average();
    long min = Long.MAX_VALUE, max = 0;
    RequestOptions opts = new RequestOptions(ResponseMode.GET_FIRST, 0).transientFlags(Message.TransientFlag.DONT_LOOPBACK);
    MethodCall call = new MethodCall((short) 0);
    int print = num / 10;
    if (oob)
        opts.flags(Message.Flag.OOB);
    if (dont_bundle)
        opts.flags(Message.Flag.DONT_BUNDLE);
    if (channel.getView().size() != 2) {
        System.err.printf("Cluster must have exactly 2 members: %s\n", channel.getView());
        return;
    }
    System.out.printf("\nInvoking %d blocking RPCs (oob: %b, dont_bundle: %b)\n", num, oob, dont_bundle);
    for (int i = 0; i < num; i++) {
        long start = System.nanoTime();
        RspList<Void> rsps = disp.callRemoteMethods(null, call, opts);
        long time_ns = System.nanoTime() - start;
        if (i > 0 && i % print == 0)
            System.out.print(".");
        boolean all_received = rsps.values().stream().allMatch(Rsp::wasReceived);
        if (!all_received)
            System.err.printf("didn't receive all responses: %s\n", rsps);
        avg.add(time_ns);
        min = Math.min(min, time_ns);
        max = Math.max(max, time_ns);
    }
    System.out.println("");
    System.out.printf("\nround-trip = min/avg/max: %.2f / %.2f / %.2f us\n\n", min / 1000.0, avg.getAverage() / 1000.0, max / 1000.0);
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) Average(org.jgroups.util.Average) MethodCall(org.jgroups.blocks.MethodCall) Rsp(org.jgroups.util.Rsp)

Example 5 with Average

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

the class MessageBundlingTest method testLatencyWithMessageBundlingAndMaxBytes.

public void testLatencyWithMessageBundlingAndMaxBytes() throws Exception {
    final int num = 500;
    final Average avg = new Average();
    long min = Long.MAX_VALUE, max = 0;
    System.out.printf(">>> sending %s messages\n", num);
    long[] times = new long[num];
    for (int i = 0; i < num; i++) {
        long start = System.nanoTime();
        a.send(new BytesMessage(null, new byte[4000]));
        promise.getResult(SLEEP);
        long time = System.nanoTime() - start;
        times[i] = time;
        avg.add(time);
        min = Math.min(min, time);
        max = Math.max(max, time);
        promise.reset(false);
    }
    for (int i = 0; i < times.length; i++) System.out.printf("latency for %d: %s\n", i, print(times[i]));
    System.out.printf("\nmin/max/avg (us): %.2f  / %.2f / %.2f\n", min / 1000.0, max / 1000.0, avg.getAverage() / 1000.0);
    assert avg.getAverage() < LATENCY_NS;
}
Also used : Average(org.jgroups.util.Average)

Aggregations

Average (org.jgroups.util.Average)5 MethodCall (org.jgroups.blocks.MethodCall)1 RequestOptions (org.jgroups.blocks.RequestOptions)1 Rsp (org.jgroups.util.Rsp)1