예제 #1
0
  public void JSONBench(int clientCount, int iterations) throws Exception {
    ServerThread server = startup();
    Thread.sleep(1000);

    JSONClient[] clients = new JSONClient[clientCount];
    for (int i = 0; i < clientCount; i++) clients[i] = new JSONClient(i, iterations);

    long execTime = 0;

    long start = System.nanoTime();
    for (JSONClient client : clients) {
      client.start();
    }
    for (JSONClient client : clients) {
      client.join();
      execTime += client.totalExecTime;
    }

    long finish = System.nanoTime();

    double seconds = (finish - start) / (1000d * 1000d * 1000d);
    double rate = (iterations * clientCount) / seconds;
    double latency = execTime / (double) (iterations * clientCount);
    latency /= 1000d * 1000d;

    System.out.printf(
        "Simple bench did %.2f iterations / sec at %.2f ms latency per txn.\n", rate, latency);

    server.shutdown();
    server.join();
  }