Search in sources :

Example 11 with RequestOptions

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

the class UnicastTestRpc method invokeRpcs.

void invokeRpcs() throws Throwable {
    if (anycasting) {
        populateAnycastList(channel.getView());
    } else {
        if ((destination = getReceiver()) == null) {
            System.err.println("UnicastTest.invokeRpcs(): receiver is null, cannot send messages");
            return;
        }
    }
    num_requests.set(0);
    System.out.println("invoking " + num_msgs + " RPCs of " + Util.printBytes(msg_size) + " on " + (anycasting ? anycast_mbrs : destination) + ", sync=" + sync + ", oob=" + oob + ", anycasting=" + anycasting);
    // The first call needs to be synchronous with OOB !
    RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 15000, anycasting, null);
    if (sync)
        options.flags(Message.Flag.DONT_BUNDLE);
    if (oob)
        options.flags(Message.Flag.OOB);
    options.mode(sync ? ResponseMode.GET_ALL : ResponseMode.GET_NONE);
    final CountDownLatch latch = new CountDownLatch(1);
    Invoker[] invokers = new Invoker[num_threads];
    for (int i = 0; i < invokers.length; i++) {
        if (anycasting)
            invokers[i] = new Invoker(anycast_mbrs, options, latch);
        else
            invokers[i] = new Invoker(destination, options, latch);
        invokers[i].setName("invoker-" + i);
        invokers[i].start();
    }
    long start = System.currentTimeMillis();
    latch.countDown();
    for (Invoker invoker : invokers) invoker.join();
    long time = System.currentTimeMillis() - start;
    System.out.println("done invoking " + num_msgs + " in " + destination);
    double time_per_req = time / (double) num_msgs;
    double reqs_sec = num_msgs / (time / 1000.0);
    double throughput = num_msgs * msg_size / (time / 1000.0);
    System.out.println(Util.bold("\ninvoked " + num_msgs + " requests in " + time + " ms: " + time_per_req + " ms/req, " + String.format("%.2f", reqs_sec) + " reqs/sec, " + Util.printBytes(throughput) + "/sec\n"));
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with RequestOptions

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

the class UPerf method startBenchmark.

/**
 * Kicks off the benchmark on all cluster nodes
 */
void startBenchmark() {
    RspList<Results> responses = null;
    try {
        RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0).flags(Message.Flag.OOB, Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
        responses = disp.callRemoteMethods(null, new MethodCall(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 : RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall) Results(org.jgroups.tests.perf.PerfUtil.Results)

Example 13 with RequestOptions

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

the class MessageDispatcherSpeedTest method sendMessages.

void sendMessages(int num) throws Exception {
    long start, stop;
    int show = num / 10;
    if (show <= 0)
        show = 1;
    start = System.currentTimeMillis();
    RequestOptions opts = new RequestOptions(ResponseMode.GET_ALL, TIMEOUT).flags(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
    byte[] data = "bla".getBytes();
    ByteArray buf = new ByteArray(data, 0, data.length);
    System.out.println("-- sending " + num + " messages");
    for (int i = 1; i <= num; i++) {
        disp.castMessage(null, new BytesMessage(null, buf), opts);
        if (i % show == 0)
            System.out.println("-- sent " + i);
    }
    stop = System.currentTimeMillis();
    printStats(stop - start, num);
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) ByteArray(org.jgroups.util.ByteArray)

Example 14 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project wildfly by wildfly.

the class ChannelCommandDispatcher method createRequestOptions.

private RequestOptions createRequestOptions(Node... excludedNodes) {
    RequestOptions options = this.createRequestOptions();
    if ((excludedNodes != null) && (excludedNodes.length > 0)) {
        Address[] addresses = new Address[excludedNodes.length];
        for (int i = 0; i < excludedNodes.length; ++i) {
            addresses[i] = getAddress(excludedNodes[i]);
        }
        options.setExclusionList(addresses);
    }
    return options;
}
Also used : Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions)

Example 15 with RequestOptions

use of org.jgroups.blocks.RequestOptions in project wildfly by wildfly.

the class ChannelCommandDispatcher method submitOnCluster.

@Override
public <R> Map<Node, Future<R>> submitOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
    Map<Node, Future<R>> results = new ConcurrentHashMap<>();
    FutureListener<RspList<R>> listener = future -> {
        try {
            future.get().keySet().stream().map(address -> this.factory.createNode(address)).forEach(node -> results.remove(node));
        } catch (CancellationException e) {
        } catch (ExecutionException e) {
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    };
    Message message = this.createMessage(command);
    RequestOptions options = this.createRequestOptions(excludedNodes);
    try {
        Future<? extends Map<Address, Rsp<R>>> futureResponses = this.dispatcher.castMessageWithFuture(null, message, options, listener);
        Set<Node> excluded = (excludedNodes != null) ? new HashSet<>(Arrays.asList(excludedNodes)) : Collections.<Node>emptySet();
        for (Address address : this.dispatcher.getChannel().getView().getMembers()) {
            Node node = this.factory.createNode(address);
            if (!excluded.contains(node)) {
                Future<R> future = new Future<R>() {

                    @Override
                    public boolean cancel(boolean mayInterruptIfRunning) {
                        return futureResponses.cancel(mayInterruptIfRunning);
                    }

                    @Override
                    public R get() throws InterruptedException, ExecutionException {
                        Map<Address, Rsp<R>> responses = futureResponses.get();
                        Rsp<R> response = responses.get(address);
                        if (response == null) {
                            throw new CancellationException();
                        }
                        return createCommandResponse(response).get();
                    }

                    @Override
                    public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                        Map<Address, Rsp<R>> responses = futureResponses.get(timeout, unit);
                        Rsp<R> response = responses.get(address);
                        if (response == null) {
                            throw new CancellationException();
                        }
                        return createCommandResponse(response).get();
                    }

                    @Override
                    public boolean isCancelled() {
                        return futureResponses.isCancelled();
                    }

                    @Override
                    public boolean isDone() {
                        return futureResponses.isDone();
                    }
                };
                results.put(node, future);
            }
        }
        return results;
    } catch (Exception e) {
        throw new CommandDispatcherException(e);
    }
}
Also used : Arrays(java.util.Arrays) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) FutureListener(org.jgroups.util.FutureListener) HashSet(java.util.HashSet) CommandDispatcher(org.wildfly.clustering.dispatcher.CommandDispatcher) Command(org.wildfly.clustering.dispatcher.Command) Future(java.util.concurrent.Future) RspFilter(org.jgroups.blocks.RspFilter) RequestOptions(org.jgroups.blocks.RequestOptions) Map(java.util.Map) RspList(org.jgroups.util.RspList) Address(org.jgroups.Address) NodeFactory(org.wildfly.clustering.group.NodeFactory) CancellationException(java.util.concurrent.CancellationException) ResponseMode(org.jgroups.blocks.ResponseMode) CommandResponse(org.wildfly.clustering.dispatcher.CommandResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Addressable(org.wildfly.clustering.server.Addressable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Message(org.jgroups.Message) Node(org.wildfly.clustering.group.Node) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Collections(java.util.Collections) MessageDispatcher(org.jgroups.blocks.MessageDispatcher) Message(org.jgroups.Message) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) RspList(org.jgroups.util.RspList) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) TimeUnit(java.util.concurrent.TimeUnit) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExecutionException(java.util.concurrent.ExecutionException)

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