コード例 #1
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
 void printView() {
   System.out.println("\n-- view: " + channel.getView() + '\n');
   try {
     System.in.skip(System.in.available());
   } catch (Exception e) {
   }
 }
コード例 #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
 private void printConnections() {
   Protocol prot = channel.getProtocolStack().findProtocol(unicast_protocols);
   if (prot instanceof UNICAST)
     System.out.println("connections:\n" + ((UNICAST) prot).printConnections());
   else if (prot instanceof UNICAST2)
     System.out.println("connections:\n" + ((UNICAST2) prot).printConnections());
 }
コード例 #4
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
 private void removeConnection() {
   Address member = getReceiver();
   if (member != null) {
     Protocol prot = channel.getProtocolStack().findProtocol(unicast_protocols);
     if (prot instanceof UNICAST) ((UNICAST) prot).removeConnection(member);
     else if (prot instanceof UNICAST2) ((UNICAST2) prot).removeConnection(member);
   }
 }
コード例 #5
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
 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());
 }
コード例 #6
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
 /** Picks the next member in the view */
 private Address getReceiver() {
   try {
     List<Address> mbrs = channel.getView().getMembers();
     int index = mbrs.indexOf(local_addr);
     int new_index = index + 1 % mbrs.size();
     return mbrs.get(new_index);
   } catch (Exception e) {
     System.err.println("UPerf.getReceiver(): " + e);
     return null;
   }
 }
コード例 #7
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
  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);
  }
コード例 #8
0
ファイル: FORK.java プロジェクト: xiongrl/JGroups
 protected void setStateInMainAndForkChannels(InputStream in) {
   try (DataInputStream input = new DataInputStream(in)) {
     for (; ; ) {
       String stack_name = Bits.readString(input);
       String ch_name = Bits.readString(input);
       int len = input.readInt();
       if (len > 0) {
         byte[] data = new byte[len];
         in.read(data, 0, len);
         ByteArrayInputStream tmp = new ByteArrayInputStream(data, 0, len);
         if (stack_name == null && ch_name == null)
           up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
         else {
           Protocol prot = fork_stacks.get(stack_name);
           if (prot == null) {
             log.warn(
                 "%s: fork stack %s not found, dropping state for %s:%s",
                 local_addr, stack_name, stack_name, ch_name);
             continue;
           }
           ForkProtocolStack fork_stack = getForkStack(prot);
           JChannel fork_ch = fork_stack.get(ch_name);
           if (fork_ch == null) {
             log.warn(
                 "%s: fork channel %s not found, dropping state for %s:%s",
                 local_addr, ch_name, stack_name, ch_name);
             continue;
           }
           fork_ch.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
         }
       }
     }
   } catch (EOFException eof) {
   } catch (Throwable ex) {
     log.error("%s: failed setting state in main channel", local_addr, ex);
   }
 }
コード例 #9
0
ファイル: FORK.java プロジェクト: xiongrl/JGroups
 protected void getStateFrom(
     JChannel channel, Protocol prot, String stack, String ch, DataOutputStream out)
     throws Exception {
   ByteArrayDataOutputStream output = new ByteArrayDataOutputStream(1024);
   OutputStreamAdapter out_ad = new OutputStreamAdapter(output);
   Event evt = new Event(Event.STATE_TRANSFER_OUTPUTSTREAM, out_ad);
   if (channel != null) channel.up(evt);
   else prot.up(evt);
   int len = output.position();
   if (len > 0) {
     Bits.writeString(stack, out);
     Bits.writeString(ch, out);
     out.writeInt(len);
     out.write(output.buffer(), 0, len);
     log.trace("%s: fetched %d bytes from %s:%s", local_addr, len, stack, ch);
   }
 }
コード例 #10
0
ファイル: UPerf.java プロジェクト: xiangxuner/JGroups
 private void removeAllConnections() {
   Protocol prot = channel.getProtocolStack().findProtocol(unicast_protocols);
   if (prot instanceof UNICAST) ((UNICAST) prot).removeAllConnections();
   else if (prot instanceof UNICAST2) ((UNICAST2) prot).removeAllConnections();
 }
コード例 #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
ファイル: JChannel.java プロジェクト: schaebo/JGroups
 protected final void init(JChannel ch) throws Exception {
   if (ch == null) throw new IllegalArgumentException("channel is null");
   prot_stack = new ProtocolStack(this);
   prot_stack.setup(
       ch.getProtocolStack()); // Setup protocol stack (creates protocol, calls init() on them)
 }