Search in sources :

Example 26 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.

the class UPerf method init.

public void init(String props, String name, AddressGenerator generator, int bind_port, boolean use_fibers) throws Throwable {
    thread_factory = new DefaultThreadFactory("invoker", false, true).useFibers(use_fibers);
    if (use_fibers && Util.fibersAvailable())
        System.out.println("-- using fibers instead of threads");
    channel = new JChannel(props).addAddressGenerator(generator).setName(name);
    if (bind_port > 0) {
        TP transport = channel.getProtocolStack().getTransport();
        transport.setBindPort(bind_port);
    }
    disp = new RpcDispatcher(channel, this).setReceiver(this).setMethodLookup(id -> METHODS[id]);
    channel.connect(groupname);
    local_addr = channel.getAddress();
    try {
        MBeanServer server = Util.getMBeanServer();
        JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
    } catch (Throwable ex) {
        System.err.println("registering the channel in JMX failed: " + ex);
    }
    if (members.size() < 2)
        return;
    Address coord = members.get(0);
    Config config = disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
    if (config != null) {
        applyConfig(config);
        System.out.println("Fetched config from " + coord + ": " + config + "\n");
    } else
        System.err.println("failed to fetch config from " + coord);
}
Also used : Property(org.jgroups.annotations.Property) Config(org.jgroups.tests.perf.PerfUtil.Config) LongAdder(java.util.concurrent.atomic.LongAdder) java.util(java.util) ResponseMode(org.jgroups.blocks.ResponseMode) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) AddressGenerator(org.jgroups.stack.AddressGenerator) IOException(java.io.IOException) MethodCall(org.jgroups.blocks.MethodCall) PutCall(org.jgroups.tests.perf.PerfUtil.PutCall) Field(java.lang.reflect.Field) GetCall(org.jgroups.tests.perf.PerfUtil.GetCall) CountDownLatch(java.util.concurrent.CountDownLatch) org.jgroups.util(org.jgroups.util) RequestOptions(org.jgroups.blocks.RequestOptions) RELAY2(org.jgroups.protocols.relay.RELAY2) MBeanServer(javax.management.MBeanServer) org.jgroups(org.jgroups) Results(org.jgroups.tests.perf.PerfUtil.Results) Method(java.lang.reflect.Method) JmxConfigurator(org.jgroups.jmx.JmxConfigurator) TP(org.jgroups.protocols.TP) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) Config(org.jgroups.tests.perf.PerfUtil.Config) TP(org.jgroups.protocols.TP) MethodCall(org.jgroups.blocks.MethodCall) MBeanServer(javax.management.MBeanServer)

Example 27 with RequestOptions

use of org.jgroups.blocks.RequestOptions 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 28 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.

the class ProgrammaticUPerf2 method eventLoop.

// ================================= end of callbacks =====================================
public void eventLoop() {
    while (looping) {
        try {
            int c = Util.keyPress(String.format(format, num_threads, time, Util.printBytes(msg_size), sync, oob, anycast_count, read_percentage, allow_local_gets, print_details, print_invokers));
            switch(c) {
                case '1':
                    startBenchmark();
                    break;
                case '2':
                    printView();
                    break;
                case '4':
                    invoke(SET_NUM_THREADS, Util.readIntFromStdin("Number of sender threads: "));
                    break;
                case '6':
                    invoke(SET_TIME, Util.readIntFromStdin("Time (secs): "));
                    break;
                case '7':
                    invoke(SET_MSG_SIZE, Util.readIntFromStdin("Message size: "));
                    break;
                case 'a':
                    int tmp = parseAnycastCount();
                    if (tmp >= 0)
                        invoke(SET_ANYCAST_COUNT, tmp);
                    break;
                case 'o':
                    invoke(SET_OOB, !oob);
                    break;
                case 's':
                    invoke(SET_SYNC, !sync);
                    break;
                case 'r':
                    double percentage = parseReadPercentage();
                    if (percentage >= 0)
                        invoke(SET_READ_PERCENTAGE, percentage);
                    break;
                case 'd':
                    invoke(PRINT_DETAILS, !print_details);
                    break;
                case 'i':
                    invoke(PRINT_INVOKERS, !print_invokers);
                    break;
                case 'l':
                    invoke(ALLOW_LOCAL_GETS, !allow_local_gets);
                    break;
                case 'v':
                    System.out.printf("Version: %s\n", Version.printVersion());
                    break;
                case 'x':
                case -1:
                    looping = false;
                    break;
                case 'X':
                    try {
                        RequestOptions options = new RequestOptions(ResponseMode.GET_NONE, 0).flags(Message.Flag.OOB, Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
                        disp.callRemoteMethods(null, new CustomCall(QUIT_ALL), options);
                        break;
                    } catch (Throwable t) {
                        System.err.println("Calling quitAll() failed: " + t);
                    }
                    break;
                default:
                    break;
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    stop();
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions)

Example 29 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.

the class ProgrammaticUPerf2 method init.

public void init(String name, String bind_addr, int bind_port) throws Exception {
    TP transport = channel.getProtocolStack().getTransport();
    disp.setServerObject(this);
    channel.setName(name);
    if (bind_port > 0)
        transport.setBindPort(bind_port);
    if (bind_addr != null)
        transport.setBindAddress(InetAddress.getByName(bind_addr));
    channel.connect(groupname);
    DiagnosticsHandler diag_handler = transport.getDiagnosticsHandler();
    if (diag_handler != null) {
        Set<DiagnosticsHandler.ProbeHandler> probe_handlers = diag_handler.getProbeHandlers();
        probe_handlers.removeIf(probe_handler -> {
            String[] keys = probe_handler.supportedKeys();
            return keys != null && Stream.of(keys).anyMatch(s -> s.startsWith("jmx"));
        });
    }
    transport.registerProbeHandler(h);
    local_addr = channel.getAddress();
    if (members.size() < 2)
        return;
    Address coord = members.get(0);
    Config config = disp.callRemoteMethod(coord, new CustomCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
    if (config != null) {
        applyConfig(config);
        System.out.println("Fetched config from " + coord + ": " + config + "\n");
    } else
        System.err.println("failed to fetch config from " + coord);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) java.util(java.util) Rsp(org.jgroups.util.Rsp) DiagnosticsHandler(org.jgroups.stack.DiagnosticsHandler) Util(org.jgroups.util.Util) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) MethodCall(org.jgroups.blocks.MethodCall) InetAddress(java.net.InetAddress) AverageMinMax(org.jgroups.util.AverageMinMax) RequestOptions(org.jgroups.blocks.RequestOptions) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.jgroups(org.jgroups) RspList(org.jgroups.util.RspList) PerfUtil(org.jgroups.tests.perf.PerfUtil) Property(org.jgroups.annotations.Property) Protocol(org.jgroups.stack.Protocol) ResponseMode(org.jgroups.blocks.ResponseMode) GMS(org.jgroups.protocols.pbcast.GMS) InetSocketAddress(java.net.InetSocketAddress) NonReflectiveProbeHandler(org.jgroups.stack.NonReflectiveProbeHandler) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) STABLE(org.jgroups.protocols.pbcast.STABLE) org.jgroups.protocols(org.jgroups.protocols) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) RequestOptions(org.jgroups.blocks.RequestOptions) NonReflectiveProbeHandler(org.jgroups.stack.NonReflectiveProbeHandler) DiagnosticsHandler(org.jgroups.stack.DiagnosticsHandler)

Example 30 with RequestOptions

use of org.jgroups.blocks.RequestOptions 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)

Aggregations

RequestOptions (org.jgroups.blocks.RequestOptions)31 MethodCall (org.jgroups.blocks.MethodCall)15 Rsp (org.jgroups.util.Rsp)10 RpcDispatcher (org.jgroups.blocks.RpcDispatcher)8 IOException (java.io.IOException)7 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 BytesMessage (org.jgroups.BytesMessage)4 Message (org.jgroups.Message)4 MessageDispatcher (org.jgroups.blocks.MessageDispatcher)4 ResponseMode (org.jgroups.blocks.ResponseMode)4 RspList (org.jgroups.util.RspList)4 Map (java.util.Map)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 org.jgroups (org.jgroups)3 Address (org.jgroups.Address)3 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)3 Method (java.lang.reflect.Method)2 InetAddress (java.net.InetAddress)2