/** Kicks off the benchmark on all cluster nodes */ void startBenchmark() throws Throwable { RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0); options.setFlags(Message.OOB, Message.DONT_BUNDLE, Message.NO_FC); RspList<Object> responses = disp.callRemoteMethods(null, new MethodCall(START), options); long total_reqs = 0; long total_time = 0; System.out.println("\n======================= Results: ==========================="); for (Map.Entry<Address, Rsp<Object>> entry : responses.entrySet()) { Address mbr = entry.getKey(); Rsp rsp = entry.getValue(); Results result = (Results) rsp.getValue(); total_reqs += result.num_gets + result.num_puts; total_time += result.time; System.out.println(mbr + ": " + result); } double total_reqs_sec = total_reqs / (total_time / 1000.0); double throughput = total_reqs_sec * msg_size; double ms_per_req = total_time / (double) total_reqs; Protocol prot = channel.getProtocolStack().findProtocol(unicast_protocols); System.out.println("\n"); System.out.println( Util.bold( "Average of " + f.format(total_reqs_sec) + " requests / sec (" + Util.printBytes(throughput) + " / sec), " + f.format(ms_per_req) + " ms /request (prot=" + prot.getName() + ")")); System.out.println("\n\n"); }
public Results startTest() throws Throwable { System.out.println( "invoking " + num_msgs + " RPCs of " + Util.printBytes(msg_size) + ", sync=" + sync + ", oob=" + oob); int total_gets = 0, total_puts = 0; final AtomicInteger num_msgs_sent = new AtomicInteger(0); Invoker[] invokers = new Invoker[num_threads]; for (int i = 0; i < invokers.length; i++) invokers[i] = new Invoker(members, num_msgs, num_msgs_sent); long start = System.currentTimeMillis(); for (Invoker invoker : invokers) invoker.start(); for (Invoker invoker : invokers) { invoker.join(); total_gets += invoker.numGets(); total_puts += invoker.numPuts(); } long total_time = System.currentTimeMillis() - start; System.out.println("done (in " + total_time + " ms)"); return new Results(total_gets, total_puts, total_time); }
void setReadPercentage() throws Exception { double tmp = Util.readDoubleFromStdin("Read percentage: "); if (tmp < 0 || tmp > 1.0) { System.err.println("read percentage must be >= 0 or <= 1.0"); return; } disp.callRemoteMethods(null, new MethodCall(SET_READ_PERCENTAGE, tmp), RequestOptions.SYNC()); }
void setAnycastCount() throws Exception { int tmp = Util.readIntFromStdin("Anycast count: "); View view = channel.getView(); if (tmp > view.size()) { System.err.println( "anycast count must be smaller or equal to the view size (" + view + ")\n"); return; } disp.callRemoteMethods(null, new MethodCall(SET_ANYCAST_COUNT, tmp), RequestOptions.SYNC()); }
public void run() { final byte[] buf = new byte[msg_size]; Object[] put_args = {0, buf}; Object[] get_args = {0}; MethodCall get_call = new MethodCall(GET, get_args); MethodCall put_call = new MethodCall(PUT, put_args); RequestOptions get_options = new RequestOptions(ResponseMode.GET_ALL, 40000, false, null); RequestOptions put_options = new RequestOptions( sync ? ResponseMode.GET_ALL : ResponseMode.GET_NONE, 40000, true, null); if (oob) { get_options.setFlags(Message.OOB); put_options.setFlags(Message.OOB); } if (sync) { get_options.setFlags(Message.DONT_BUNDLE, Message.NO_FC); put_options.setFlags(Message.DONT_BUNDLE, Message.NO_FC); } while (true) { long i = num_msgs_sent.getAndIncrement(); if (i >= num_msgs_to_send) break; boolean get = Util.tossWeightedCoin(read_percentage); try { if (get) { // sync GET Address target = pickTarget(); get_args[0] = i; disp.callRemoteMethod(target, get_call, get_options); num_gets++; } else { // sync or async (based on value of 'sync') PUT Collection<Address> targets = pickAnycastTargets(); put_args[0] = i; disp.callRemoteMethods(targets, put_call, put_options); num_puts++; } } catch (Throwable throwable) { throwable.printStackTrace(); } } }
public void init(String props, String name) throws Throwable { channel = new JChannel(props); if (name != null) channel.setName(name); disp = new RpcDispatcher(channel, null, this, this); disp.setMethodLookup( new MethodLookup() { public Method findMethod(short id) { return METHODS[id]; } }); disp.setRequestMarshaller(new CustomMarshaller()); 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); ConfigOptions config = (ConfigOptions) disp.callRemoteMethod( coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000)); if (config != null) { this.oob = config.oob; this.sync = config.sync; this.num_threads = config.num_threads; this.num_msgs = config.num_msgs; this.msg_size = config.msg_size; this.anycast_count = config.anycast_count; this.read_percentage = config.read_percentage; System.out.println("Fetched config from " + coord + ": " + config); } else System.err.println("failed to fetch config from " + coord); }
void setMessageSize() throws Exception { int tmp = Util.readIntFromStdin("Message size: "); disp.callRemoteMethods(null, new MethodCall(SET_MSG_SIZE, tmp), RequestOptions.SYNC()); }
void setNumMessages() throws Exception { int tmp = Util.readIntFromStdin("Number of RPCs: "); disp.callRemoteMethods(null, new MethodCall(SET_NUM_MSGS, tmp), RequestOptions.SYNC()); }
void setSenderThreads() throws Exception { int threads = Util.readIntFromStdin("Number of sender threads: "); disp.callRemoteMethods(null, new MethodCall(SET_NUM_THREADS, threads), RequestOptions.SYNC()); }
public void eventLoop() throws Throwable { int c; while (true) { c = Util.keyPress( "[1] Send msgs [2] Print view [3] Print conns " + "[4] Trash conn [5] Trash all conns" + "\n[6] Set sender threads (" + num_threads + ") [7] Set num msgs (" + num_msgs + ") " + "[8] Set msg size (" + Util.printBytes(msg_size) + ")" + " [9] Set anycast count (" + anycast_count + ")" + "\n[o] Toggle OOB (" + oob + ") [s] Toggle sync (" + sync + ") [r] Set read percentage (" + f.format(read_percentage) + ")" + "\n[q] Quit\n"); switch (c) { case -1: break; case '1': try { startBenchmark(); } catch (Throwable t) { System.err.println(t); } break; case '2': printView(); break; case '3': printConnections(); break; case '4': removeConnection(); break; case '5': removeAllConnections(); break; case '6': setSenderThreads(); break; case '7': setNumMessages(); break; case '8': setMessageSize(); break; case '9': setAnycastCount(); break; case 'o': boolean new_value = !oob; disp.callRemoteMethods(null, new MethodCall(SET_OOB, new_value), RequestOptions.SYNC()); break; case 's': boolean new_val = !sync; disp.callRemoteMethods(null, new MethodCall(SET_SYNC, new_val), RequestOptions.SYNC()); break; case 'r': setReadPercentage(); break; case 'q': channel.close(); return; case '\n': case '\r': break; default: break; } } }
void stop() { if (disp != null) disp.stop(); Util.close(channel); }