コード例 #1
0
ファイル: UnicastTest.java プロジェクト: xiongrl/JGroups
    public void receive(Message msg) {
      byte[] buf = msg.getRawBuffer();
      byte type = buf[msg.getOffset()];

      switch (type) {
        case START:
          ByteBuffer tmp = ByteBuffer.wrap(buf, 1 + msg.getOffset(), Global.LONG_SIZE);
          num_msgs = (int) tmp.getLong();
          print = num_msgs / 10;
          current_value.set(0);
          total_bytes.set(0);
          start = System.currentTimeMillis();
          break;
        case DATA:
          long new_val = current_value.incrementAndGet();
          total_bytes.addAndGet(msg.getLength() - Global.INT_SIZE);
          if (print > 0 && new_val % print == 0) System.out.println("received " + new_val);
          if (new_val >= num_msgs) {
            long time = System.currentTimeMillis() - start;
            double msgs_sec = (current_value.get() / (time / 1000.0));
            double throughput = total_bytes.get() / (time / 1000.0);
            System.out.println(
                String.format(
                    "\nreceived %d messages in %d ms (%.2f msgs/sec), throughput=%s",
                    current_value.get(), time, msgs_sec, Util.printBytes(throughput)));
            break;
          }
          break;
        default:
          System.err.println("Type " + type + " is invalid");
      }
    }
コード例 #2
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
  /** 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");
  }
コード例 #3
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
  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);
  }
コード例 #4
0
ファイル: STATE_TRANSFER.java プロジェクト: xiongrl/JGroups
 /** Set the digest and the send the state up to the application */
 protected void handleStateRsp(final Digest digest, Address sender, byte[] state) {
   try {
     if (isDigestNeeded()) {
       punchHoleFor(sender);
       closeBarrierAndSuspendStable(); // fix for https://jira.jboss.org/jira/browse/JGRP-1013
       if (digest != null)
         down_prot.down(
             new Event(Event.OVERWRITE_DIGEST, digest)); // set the digest (e.g. in NAKACK)
     }
     waiting_for_state_response = false;
     stop = System.currentTimeMillis();
     log.debug(
         "%s: received state, size=%s, time=%d milliseconds",
         local_addr, (state == null ? "0" : Util.printBytes(state.length)), stop - start);
     StateTransferResult result = new StateTransferResult(state);
     up_prot.up(new Event(Event.GET_STATE_OK, result));
     down_prot.down(
         new Event(Event.GET_VIEW_FROM_COORD)); // https://issues.jboss.org/browse/JGRP-1751
   } catch (Throwable t) {
     handleException(t);
   } finally {
     if (isDigestNeeded()) {
       closeHoleFor(sender);
       openBarrierAndResumeStable();
     }
   }
 }
コード例 #5
0
  public void eventLoop() throws Exception {
    int c;

    while (true) {
      System.out.print(
          "[1] Send msgs "
              + "\n[6]Set sender threads ("
              + num_threads
              + ") [7] Set num msgs ("
              + num_msgs
              + ") "
              + "[8] Set msg size ("
              + Util.printBytes(msg_size)
              + ")"
              + "\n[o] Toggle OOB ("
              + oob
              + ") [b] Toggle dont_bundle ("
              + dont_bundle
              + ")\n[q] Quit\n");
      System.out.flush();
      c = System.in.read();
      switch (c) {
        case -1:
          break;
        case '1':
          sendMessages();
          break;
        case '6':
          setSenderThreads();
          break;
        case '7':
          setNumMessages();
          break;
        case '8':
          setMessageSize();
          break;
        case 'o':
          oob = !oob;
          System.out.println("oob=" + oob);
          break;
        case 'b':
          dont_bundle = !dont_bundle;
          System.out.println("dont_bundle = " + dont_bundle);
          break;
        case 'q':
          Util.close(srv_sock);
          Util.close(sock);
          return;
        default:
          break;
      }
    }
  }
コード例 #6
0
  void sendMessages() throws Exception {
    if (num_threads > 1 && num_msgs % num_threads != 0) {
      System.err.println(
          "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
      return;
    }

    System.out.println(
        "sending "
            + num_msgs
            + " messages ("
            + Util.printBytes(msg_size)
            + ") to "
            + remote
            + ": oob="
            + oob
            + ", "
            + num_threads
            + " sender thread(s)");
    ByteBuffer buf =
        ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
    Message msg = new Message(null, buf.array());
    // msg.writeTo(output);

    ExposedByteArrayOutputStream out_stream = new ExposedByteArrayOutputStream((int) (msg.size()));
    ExposedDataOutputStream dos = new ExposedDataOutputStream(out_stream);
    byte flags = 0;
    dos.writeShort(Version.version); // write the version
    if (msg.getDest() == null) flags += (byte) 2;
    dos.writeByte(flags);
    msg.writeTo(dos);
    Buffer buffer = new Buffer(out_stream.getRawBuffer(), 0, out_stream.size());

    output_lock.lock(); // need to sync if we have more than 1 sender
    try {
      // msg.writeTo(output);
      output.writeInt(buffer.getLength());
      output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength());
    } finally {
      output_lock.unlock();
    }

    int msgs_per_sender = num_msgs / num_threads;
    Sender[] senders = new Sender[num_threads];
    for (int i = 0; i < senders.length; i++)
      senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10);
    for (Sender sender : senders) sender.start();
    for (Sender sender : senders) sender.join();
    output.flush();
    System.out.println("done sending " + num_msgs + " to " + remote);
  }
コード例 #7
0
ファイル: UdpPerf.java プロジェクト: pulasthi/JGroups
  protected void handleData() {
    if (last_interval == 0) last_interval = System.currentTimeMillis();

    long received_so_far = total_received_msgs.incrementAndGet();
    if (received_so_far % receive_log_interval == 0) {
      long curr_time = System.currentTimeMillis();
      long diff = curr_time - last_interval;
      double msgs_sec = receive_log_interval / (diff / 1000.0);
      double throughput = msgs_sec * msg_size;
      last_interval = curr_time;
      System.out.println(
          String.format(
              "-- received %d msgs %d ms, %.2g msgs/sec, %s / sec)",
              received_so_far, diff, msgs_sec, Util.printBytes(throughput)));
    }
  }
コード例 #8
0
ファイル: STATE_TRANSFER.java プロジェクト: xiongrl/JGroups
  protected void getStateFromApplication(Address requester, Digest digest) {
    StateTransferInfo rsp = (StateTransferInfo) up_prot.up(new Event(Event.GET_APPLSTATE));
    byte[] state = rsp.state;

    if (stats) {
      num_state_reqs.incrementAndGet();
      if (state != null) num_bytes_sent.addAndGet(state.length);
      avg_state_size = num_bytes_sent.doubleValue() / num_state_reqs.doubleValue();
    }

    Message state_rsp =
        new Message(requester, state)
            .putHeader(this.id, new StateHeader(StateHeader.STATE_RSP, digest));
    log.trace(
        "%s: sending state to %s (size=%s)",
        local_addr, state_rsp.getDest(), Util.printBytes(state != null ? state.length : 0));
    down_prot.down(new Event(Event.MSG, state_rsp));
  }
コード例 #9
0
ファイル: UnicastTest.java プロジェクト: xiongrl/JGroups
  void sendMessages() throws Exception {
    Address destination = getReceiver();
    if (destination == null) {
      System.err.println("UnicastTest.sendMessages(): receiver is null, cannot send messages");
      return;
    }

    if (num_threads > 1 && num_msgs % num_threads != 0) {
      System.err.println(
          "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")");
      return;
    }

    System.out.println(
        "sending "
            + num_msgs
            + " messages ("
            + Util.printBytes(msg_size)
            + ") to "
            + destination
            + ": oob="
            + oob
            + ", "
            + num_threads
            + " sender thread(s)");
    ByteBuffer buf =
        ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs);
    Message msg = new Message(destination, buf.array());
    channel.send(msg);

    long print = num_msgs / 10;
    int msgs_per_sender = num_msgs / num_threads;
    Sender[] senders = new Sender[num_threads];
    for (int i = 0; i < senders.length; i++)
      senders[i] = new Sender(msgs_per_sender, msg_size, destination, (int) print);
    for (Sender sender : senders) sender.start();
    for (Sender sender : senders) sender.join();
    System.out.println("done sending " + num_msgs + " to " + destination);
  }
コード例 #10
0
ファイル: UtilTest.java プロジェクト: Sk464036801/JGroups
  public static void testPrintBytes() {
    long num;
    String s;

    num = 1;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1b", s);

    num = 999;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("999b", s);

    num = 1000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1KB", s);

    num = 1001;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1KB", s);

    num = 1010;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1.01KB", s);

    num = 1543;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1.54KB", s);

    num = 10000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("10KB", s);

    num = 150000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("150KB", s);

    num = 150023;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("150.02KB", s);

    num = 1200000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1.2MB", s);

    num = 150000000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("150MB", s);

    num = 150030000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("150.03MB", s);

    num = 1200000000;
    s = Util.printBytes(num);
    System.out.println(num + " is " + s);
    Assert.assertEquals("1.2GB", s);
  }
コード例 #11
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
  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;
      }
    }
  }
コード例 #12
0
ファイル: UnicastTest.java プロジェクト: xiongrl/JGroups
  public void eventLoop() throws Exception {
    int c;

    while (true) {
      System.out.print(
          "[1] Send msgs [2] Print view [3] Print conns [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)
              + ")"
              + "\n[o] Toggle OOB ("
              + oob
              + ") [b] Toggle dont_bundle ("
              + dont_bundle
              + ")\n[q] Quit\n");
      System.out.flush();
      c = System.in.read();
      switch (c) {
        case -1:
          break;
        case '1':
          sendMessages();
          break;
        case '2':
          printView();
          break;
        case '3':
          printConnections();
          break;
        case '5':
          removeAllConnections();
          break;
        case '6':
          setSenderThreads();
          break;
        case '7':
          setNumMessages();
          break;
        case '8':
          setMessageSize();
          break;
        case 'o':
          oob = !oob;
          System.out.println("oob=" + oob);
          break;
        case 'b':
          dont_bundle = !dont_bundle;
          System.out.println("dont_bundle = " + dont_bundle);
          break;
        case 'q':
          channel.close();
          return;
        default:
          break;
      }
    }
  }