Ejemplo n.º 1
0
 @Override
 public void clientCallback(ClientResponse clientResponse) {
   // Track the result of the request (Success, Failure)
   long now = System.currentTimeMillis();
   if (clientResponse.getStatus() == ClientResponse.SUCCESS) {
     TrackingResults.incrementAndGet(0);
     long txid = clientResponse.getResults()[0].asScalarLong();
     final String trace = String.format("%d:%d:%d\n", m_rowid, txid, now);
     try {
       m_writer.write(TxnEgo.getPartitionId(txid), trace);
     } catch (IOException e) {
       e.printStackTrace();
     }
   } else {
     TrackingResults.incrementAndGet(1);
     final String trace = String.format("%d:-1:%d\n", m_rowid, now);
     try {
       m_writer.write(-1, trace);
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 2
0
  // Application entry point
  public static void main(String[] args) {
    try {

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

      // Use the AppHelper utility class to retrieve command line application parameters

      // Define parameters and pull from command line
      AppHelper apph =
          new AppHelper(AsyncBenchmark.class.getCanonicalName())
              .add(
                  "displayinterval",
                  "display_interval_in_seconds",
                  "Interval for performance feedback, in seconds.",
                  10)
              .add("duration", "run_duration_in_seconds", "Benchmark duration, in seconds.", 120)
              .add(
                  "servers",
                  "comma_separated_server_list",
                  "List of VoltDB servers to connect to.",
                  "localhost")
              .add("port", "port_number", "Client port to connect to on cluster nodes.", 21212)
              .add(
                  "poolsize",
                  "pool_size",
                  "Size of the record pool to operate on - larger sizes will cause a higher insert/update-delete rate.",
                  100000)
              .add(
                  "procedure",
                  "procedure_name",
                  "Procedure to call.",
                  "JiggleExportSinglePartition")
              .add(
                  "ratelimit",
                  "rate_limit",
                  "Rate limit to start from (number of transactions per second).",
                  100000)
              .add(
                  "autotune",
                  "auto_tune",
                  "Flag indicating whether the benchmark should self-tune the transaction rate for a target execution latency (true|false).",
                  "true")
              .add(
                  "latencytarget",
                  "latency_target",
                  "Execution latency to target to tune transaction rate (in milliseconds).",
                  10)
              .add("catalogswap", "Swap catalogs from the client", "true")
              .setArguments(args);

      config = new ConnectionConfig(apph);

      // Retrieve parameters
      final boolean catalogSwap = apph.booleanValue("catalogswap");
      final String csv = apph.stringValue("statsfile");

      TxnIdWriter writer = new TxnIdWriter("dude", "clientlog");

      // Validate parameters
      apph.validate("duration", (config.duration > 0))
          .validate("poolsize", (config.poolSize > 0))
          .validate("ratelimit", (config.rateLimit > 0))
          .validate("latencytarget", (config.latencyTarget > 0));

      // Display actual parameters, for reference
      apph.printActualUsage();

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

      // Get a client connection - we retry for a while in case the server hasn't started yet
      createClient();
      connect();

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

      // Create a Timer task to display performance data on the procedure
      Timer timer = new Timer(true);
      timer.scheduleAtFixedRate(
          new TimerTask() {
            @Override
            public void run() {
              printStatistics(periodicStatsContext, true);
            }
          },
          config.displayInterval * 1000l,
          config.displayInterval * 1000l);

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

      benchmarkStartTS = System.currentTimeMillis();
      AtomicLong rowId = new AtomicLong(0);

      // Run the benchmark loop for the requested duration
      final long endTime = benchmarkStartTS + (1000l * config.duration);
      int swap_count = 0;
      boolean first_cat = false;
      while (endTime > System.currentTimeMillis()) {
        long currentRowId = rowId.incrementAndGet();
        // Post the request, asynchronously
        try {
          clientRef
              .get()
              .callProcedure(
                  new AsyncCallback(writer, currentRowId), config.procedure, currentRowId, 0);
        } catch (Exception e) {
          e.printStackTrace();
          System.exit(-1);
        }

        swap_count++;
        if (((swap_count % CATALOG_SWAP_INTERVAL) == 0) && catalogSwap) {
          System.out.println("Changing catalogs...");
          clientRef.get().updateApplicationCatalog(catalogs[first_cat ? 0 : 1], deployment);
          first_cat = !first_cat;
        }
      }
      shutdown.compareAndSet(false, true);

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

      // We're done - stop the performance statistics display task
      timer.cancel();

      // ---------------------------------------------------------------------------------------------------------------------------------------------------
      clientRef.get().drain();

      Thread.sleep(10000);
      waitForStreamedAllocatedMemoryZero(clientRef.get());
      System.out.println("Writing export count as: " + TrackingResults.get(0));
      // Write to export table to get count to be expected on other side.
      clientRef.get().callProcedure("JiggleExportDoneTable", TrackingResults.get(0));
      writer.close(true);

      // Now print application results:

      // 1. Tracking statistics
      System.out.printf(
          "-------------------------------------------------------------------------------------\n"
              + " Benchmark Results\n"
              + "-------------------------------------------------------------------------------------\n\n"
              + "A total of %d calls was received...\n"
              + " - %,9d Succeeded\n"
              + " - %,9d Failed (Transaction Error)\n"
              + "\n\n"
              + "-------------------------------------------------------------------------------------\n",
          TrackingResults.get(0) + TrackingResults.get(1),
          TrackingResults.get(0),
          TrackingResults.get(1));

      // 3. Performance statistics (we only care about the procedure that we're benchmarking)
      System.out.println(
          "\n\n-------------------------------------------------------------------------------------\n"
              + " System Statistics\n"
              + "-------------------------------------------------------------------------------------\n\n");
      printStatistics(fullStatsContext, false);

      // Dump statistics to a CSV file
      clientRef.get().writeSummaryCSV(fullStatsContext.getStatsByProc().get(config.procedure), csv);

      clientRef.get().close();

      // ---------------------------------------------------------------------------------------------------------------------------------------------------

    } catch (Exception x) {
      System.out.println("Exception: " + x);
      x.printStackTrace();
    }
  }