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"));
}
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");
}
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);
}
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;
}
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);
}
}
Aggregations