Пример #1
0
  private void send(
      final Address dest, final int num_msgs, final int num_threads, final double oob_prob)
      throws Exception {
    if (num_threads <= 0) throw new IllegalArgumentException("number of threads <= 0");

    if (num_msgs % num_threads != 0)
      throw new IllegalArgumentException(
          "number of messages ( "
              + num_msgs
              + ") needs to be divisible by "
              + "the number o threads ("
              + num_threads
              + ")");

    if (num_threads > 1) {
      final int msgs_per_thread = num_msgs / num_threads;
      Thread[] threads = new Thread[num_threads];
      final AtomicInteger counter = new AtomicInteger(0);
      for (int i = 0; i < threads.length; i++) {
        threads[i] =
            new Thread() {
              public void run() {
                for (int j = 0; j < msgs_per_thread; j++) {
                  Channel sender = Util.tossWeightedCoin(0.5) ? a : b;
                  boolean oob = Util.tossWeightedCoin(oob_prob);
                  int num = counter.incrementAndGet();
                  Message msg = new Message(dest, null, num);
                  if (oob) msg.setFlag(Message.OOB);
                  try {
                    sender.send(msg);
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              }
            };
        threads[i].start();
      }
      for (int i = 0; i < threads.length; i++) {
        threads[i].join(20000);
      }
      return;
    }

    for (int i = 0; i < num_msgs; i++) {
      Channel sender = Util.tossWeightedCoin(0.5) ? a : b;
      boolean oob = Util.tossWeightedCoin(oob_prob);
      Message msg = new Message(dest, null, i);
      if (oob) msg.setFlag(Message.OOB);
      sender.send(msg);
    }
  }
Пример #2
0
    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();
        }
      }
    }