예제 #1
0
  /** 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");
  }
예제 #2
0
  /**
   * Sends a unicast message and - depending on the options - returns a result
   *
   * @param msg the message to be sent. The destination needs to be non-null
   * @param opts the options to be used
   * @return T the result
   * @throws Exception If there was problem sending the request, processing it at the receiver, or
   *     processing it at the sender.
   * @throws TimeoutException If the call didn't succeed within the timeout defined in options (if
   *     set)
   */
  public <T> T sendMessage(Message msg, RequestOptions opts) throws Exception {
    Address dest = msg.getDest();
    if (dest == null)
      throw new IllegalArgumentException("message destination is null, cannot send message");

    if (opts != null) {
      msg.setFlag(opts.getFlags()).setTransientFlag(opts.getTransientFlags());
      if (opts.getScope() > 0) msg.setScope(opts.getScope());
      if (opts.getMode() == ResponseMode.GET_NONE) async_unicasts.incrementAndGet();
      else sync_unicasts.incrementAndGet();
    }

    UnicastRequest<T> req = new UnicastRequest<T>(msg, corr, dest, opts);
    req.execute();

    if (opts != null && opts.getMode() == ResponseMode.GET_NONE) return null;

    Rsp<T> rsp = req.getResult();
    if (rsp.wasSuspected()) throw new SuspectedException(dest);

    Throwable exception = rsp.getException();
    if (exception != null) {
      if (exception instanceof Error) throw (Error) exception;
      else if (exception instanceof RuntimeException) throw (RuntimeException) exception;
      else if (exception instanceof Exception) throw (Exception) exception;
      else throw new RuntimeException(exception);
    }

    if (rsp.wasUnreachable()) throw new UnreachableException(dest);
    if (!rsp.wasReceived() && !req.responseReceived())
      throw new TimeoutException("timeout sending message to " + dest);
    return rsp.getValue();
  }