Example #1
0
    private void rateControlledRunLoop() {
      m_lastRequestTime = System.currentTimeMillis();
      while (true) {
        boolean bp = false;
        /*
         * If there is back pressure don't send any requests. Update the
         * last request time so that a large number of requests won't
         * queue up to be sent when there is no longer any back
         * pressure.
         */
        try {
          m_voltClient.backpressureBarrier();
        } catch (InterruptedException e1) {
          throw new RuntimeException();
        }

        final long now = System.currentTimeMillis();

        /*
         * Generate the correct number of transactions based on how much
         * time has passed since the last time transactions were sent.
         */
        final long delta = now - m_lastRequestTime;
        if (delta > 0) {
          final int transactionsToCreate = (int) (delta * m_txnsPerMillisecond);
          if (transactionsToCreate < 1) {
            Thread.yield();
            continue;
          }

          for (int ii = 0; ii < transactionsToCreate; ii++) {
            try {
              bp = !runOnce();
              if (bp) {
                m_lastRequestTime = now;
                break;
              }
            } catch (final IOException e) {
              return;
            }
          }
        } else {
          Thread.yield();
        }

        m_lastRequestTime = now;
      }
    }
Example #2
0
    @Override
    public void run() {
      if (m_txnRate == -1) {
        if (m_sampler != null) {
          m_sampler.start();
        }
        try {
          runLoop();
        } catch (final IOException e) {
        } catch (final InterruptedException e) {
        }
      } else {
        System.err.println(
            "Running rate controlled m_txnRate == "
                + m_txnRate
                + " m_txnsPerMillisecond == "
                + m_txnsPerMillisecond);
        System.err.flush();
        rateControlledRunLoop();
      }

      if (m_exitOnCompletion) {
        System.exit(0);
      }
    }
Example #3
0
    public void answerPoll() {
      final StringBuilder txncounts = new StringBuilder();
      synchronized (m_counts) {
        for (int i = 0; i < m_counts.length; ++i) {
          txncounts.append(",");
          txncounts.append(m_countDisplayNames[i]);
          txncounts.append(",");
          txncounts.append(m_counts[i].get());
        }
      }

      // For now, sum the latency buckets and send them across
      // with the magic key "@@ClientLatencyBuckets" Delimit
      // the buckets with "--", to avoid the normalized commas
      // whitespace characters. Gah. Hack.
      VoltTable clientRTTLatencies = m_voltClient.getClientRTTLatencies();
      long[] latencies = latencySummaryHelper(clientRTTLatencies);
      txncounts.append(", @@ClientLatencyBuckets,");
      for (int i = 0; i < latencies.length; i++) {
        txncounts.append(latencies[i]);
        txncounts.append("--");
      }

      VoltTable clusterRTTLatencies = m_voltClient.getClusterRTTLatencies();
      latencies = latencySummaryHelper(clusterRTTLatencies);
      txncounts.append(", @@ClusterLatencyBuckets,");
      for (int i = 0; i < latencies.length; i++) {
        txncounts.append(latencies[i]);
        txncounts.append("--");
      }

      System.out.printf(
          "%d,%s%s\n", System.currentTimeMillis(), m_controlState.display, txncounts.toString());
    }
Example #4
0
 /**
  * Derived classes implementing a main that will be invoked at the start of the app should call
  * this main to instantiate themselves
  *
  * @param clientClass Derived class to instantiate
  * @param args
  * @param startImmediately Whether to start the client thread immediately or not.
  */
 public static void main(
     final Class<? extends ClientMain> clientClass,
     final String args[],
     final boolean startImmediately) {
   try {
     final Constructor<? extends ClientMain> constructor =
         clientClass.getConstructor(new Class<?>[] {new String[0].getClass()});
     final ClientMain clientMain = constructor.newInstance(new Object[] {args});
     if (startImmediately) {
       final ControlWorker worker = clientMain.new ControlWorker();
       worker.start();
       // Wait for the worker to finish
       worker.join();
     } else {
       clientMain.start();
     }
   } catch (final Exception e) {
     e.printStackTrace();
     System.exit(-1);
   }
 }
Example #5
0
 public void answerWithError() {
   System.out.printf("%d,%s,%s\n", System.currentTimeMillis(), m_controlState.display, m_reason);
 }
Example #6
0
    public void run() {
      String command = "";
      final InputStreamReader reader = new InputStreamReader(System.in);
      final BufferedReader in = new BufferedReader(reader);

      // transition to ready and send ready message
      if (m_controlState == ControlState.PREPARING) {
        System.out.printf("%d,%s\n", System.currentTimeMillis(), ControlState.READY.display);
        m_controlState = ControlState.READY;
      } else {
        System.err.println("Error - not starting prepared!");
        System.err.println(m_controlState.display + " " + m_reason);
      }

      while (true) {
        try {
          command = in.readLine();
        } catch (final IOException e) {
          // Hm. quit?
          System.err.println("Error on standard input: " + e.getMessage());
          System.exit(-1);
        }

        if (command.equalsIgnoreCase("START")) {
          if (m_controlState != ControlState.READY) {
            setState(ControlState.ERROR, "START when not READY.");
            answerWithError();
            continue;
          }
          answerStart();
          m_controlState = ControlState.RUNNING;
        } else if (command.equalsIgnoreCase("POLL")) {
          if (m_controlState != ControlState.RUNNING) {
            setState(ControlState.ERROR, "POLL when not RUNNING.");
            answerWithError();
            continue;
          }
          answerPoll();
        } else if (command.equalsIgnoreCase("STOP")) {
          if (m_controlState == ControlState.RUNNING) {
            try {
              if (m_sampler != null) {
                m_sampler.setShouldStop();
                m_sampler.join();
              }
              m_voltClient.close();
              if (m_checkTables) {
                checkTables();
              }
            } catch (InterruptedException e) {
              System.exit(0);
            }
            System.exit(0);
          }
          System.err.println("Error: STOP when not RUNNING");
          System.exit(-1);
        } else {
          System.err.println("Error on standard input: unknown command " + command);
          System.exit(-1);
        }
      }
    }