Exemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    BenchMarkOptions options = BenchMarkOptions.parse(args.length > 0 ? args : DEFAULT_ARGS);
    if (null == options) {
      BenchMarkOptions.printUseage();
      return;
    }

    CabinetManager.Client client =
        new CabinetManager.Client(options.getEventThreads(), Executors.defaultThreadFactory());
    SocketAddress remote = new InetSocketAddress(options.getHost(), options.getPort());
    for (int i = 0; i < options.getConnections(); i++) {
      client.connect(remote, options.isAsync(), MAX_MESSAGE_SIZE, TBinaryProtocol.FACTORY);
    }

    if (options.getDelay() > 0) {
      Thread.sleep(options.getDelay());
    }

    CountDownLatch countDownLatch = new CountDownLatch(options.getThreads());
    // PerformanceStats.startLoggingThread();
    final long start = System.currentTimeMillis();
    CabinetManagerTest[] tests = new CabinetManagerTest[options.getThreads()];
    for (int i = 0; i < options.getThreads(); i++) {
      tests[i] =
          new CabinetManagerTest(client, options.getRequests(), options.getSleep(), countDownLatch);
      new Thread(tests[i]).start();
    }
    countDownLatch.await();
    long total = 0, ok = 0, error = 0;
    for (int i = 0; i < options.getThreads(); i++) {
      total += tests[i].total.get();
      ok += tests[i].ok.get();
      error += tests[i].error.get();
    }
    System.out.format("send %d requests\n", total);
    long time = System.currentTimeMillis() - start;
    System.out.format("time: %d, ok: %d, error: %d\n", time, ok, error);
    System.out.format("%d qps\n", total * 1000 / time);
    System.out.println(PerformanceStats.statString());
    System.exit(0);
  }
Exemplo n.º 2
0
 private void stat(TMessage msg, long start) {
   long now = System.currentTimeMillis();
   long cost = System.currentTimeMillis() - start;
   LOGGER.debug("[{}] recv {}, cost {}", now, msg.seqid, cost);
   requestStat.stat(cost);
 }
Exemplo n.º 3
0
public class CabinetManagerTest implements Runnable {
  private static final PerformanceStats requestStat = PerformanceStats.newStat("zamplus");
  private static final Logger LOGGER = LoggerFactory.getLogger(CabinetManagerTest.class);

  private final AtomicInteger total = new AtomicInteger(0);
  private final AtomicInteger ok = new AtomicInteger(0);
  private final AtomicInteger error = new AtomicInteger(0);

  private final CabinetManager.Client client;
  private final int n;
  private final CountDownLatch countDownLatch;
  private final int sleep;

  public CabinetManagerTest(
      CabinetManager.Client client, int n, int sleep, CountDownLatch countDownLatch) {
    super();
    this.client = client;
    this.n = n;
    this.sleep = sleep;
    this.countDownLatch = countDownLatch;
  }

  private void stat(TMessage msg, long start) {
    long now = System.currentTimeMillis();
    long cost = System.currentTimeMillis() - start;
    LOGGER.debug("[{}] recv {}, cost {}", now, msg.seqid, cost);
    requestStat.stat(cost);
  }

  @Override
  public void run() {
    for (int i = 0; i < n; i++) {
      try {
        final long start = System.currentTimeMillis();
        // LOGGER.info("[{}]", start);
        Sync sync =
            client.QueryItem(
                new QueryItemREQ(String.valueOf(i).getBytes("UTF-8")),
                "test_kv2",
                new AsyncHandler<TCall<QueryItem_args, QueryItem_result>>() {

                  @Override
                  public void operationCompleted(TCall<QueryItem_args, QueryItem_result> call) {
                    stat(call.getMessage(), start);
                    ok.incrementAndGet();
                    if (total.incrementAndGet() == n) {
                      countDownLatch.countDown();
                    }
                  }

                  @Override
                  public void operationFailed(
                      TCall<QueryItem_args, QueryItem_result> call, TException e) {
                    error.incrementAndGet();
                    if (total.incrementAndGet() == n) {
                      countDownLatch.countDown();
                    }
                    LOGGER.error("", e);
                  }
                });
        if (sleep > 0 && i % sleep == 0) {
          sync.sync();
        }
        Thread.sleep(1000);
        System.out.println(i);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  private static final String[] DEFAULT_ARGS = "-h 61.152.223.3 -n 10000 -s 1 -a".split(" ");
  private static final int MAX_MESSAGE_SIZE = 65535;

  public static void main(String[] args) throws Exception {
    BenchMarkOptions options = BenchMarkOptions.parse(args.length > 0 ? args : DEFAULT_ARGS);
    if (null == options) {
      BenchMarkOptions.printUseage();
      return;
    }

    CabinetManager.Client client =
        new CabinetManager.Client(options.getEventThreads(), Executors.defaultThreadFactory());
    SocketAddress remote = new InetSocketAddress(options.getHost(), options.getPort());
    for (int i = 0; i < options.getConnections(); i++) {
      client.connect(remote, options.isAsync(), MAX_MESSAGE_SIZE, TBinaryProtocol.FACTORY);
    }

    if (options.getDelay() > 0) {
      Thread.sleep(options.getDelay());
    }

    CountDownLatch countDownLatch = new CountDownLatch(options.getThreads());
    // PerformanceStats.startLoggingThread();
    final long start = System.currentTimeMillis();
    CabinetManagerTest[] tests = new CabinetManagerTest[options.getThreads()];
    for (int i = 0; i < options.getThreads(); i++) {
      tests[i] =
          new CabinetManagerTest(client, options.getRequests(), options.getSleep(), countDownLatch);
      new Thread(tests[i]).start();
    }
    countDownLatch.await();
    long total = 0, ok = 0, error = 0;
    for (int i = 0; i < options.getThreads(); i++) {
      total += tests[i].total.get();
      ok += tests[i].ok.get();
      error += tests[i].error.get();
    }
    System.out.format("send %d requests\n", total);
    long time = System.currentTimeMillis() - start;
    System.out.format("time: %d, ok: %d, error: %d\n", time, ok, error);
    System.out.format("%d qps\n", total * 1000 / time);
    System.out.println(PerformanceStats.statString());
    System.exit(0);
  }
}