title: Calculating the throughput in multithreading code
body: <p>I am doing <code>bench marking</code> on some of my client code. Now I am trying to find out how to calculate the throughput from my <code>Multithreading</code> code-</p>
  
  <p>I am running my program with <code>20 threads</code>. And each thread is going to run for <code>15 minutes</code>, so all the <code>20 threads will run for 15 minutes</code>.</p>
  
  <p>Below is my code-</p>
  
  <pre><code>public static void main(String[] args) {
  
  try {
  
          // create thread pool with given size
          ExecutorService service = Executors.newFixedThreadPool(20);
  
          // queue some tasks
          long startTime = System.currentTimeMillis();
          long endTime = startTime + (15 * 60 * 1000);
  
          for (int i = 0; i &lt; 20; i++) {
              service.submit(new CassandraReadTask(endTime, columnFamilyList));
          }
  
          service.shutdown();
          service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
      } catch (Exception e) {
          LOG.warn("Threw a Exception in" + CNAME + e);
      }
  }
  </code></pre>
  
  <p>Below is my class that implements <code>Runnable interface</code>-</p>
  
  <pre><code>class CassandraReadTask implements Runnable {
  
      public void run() {
  
          try {
  
              while (System.currentTimeMillis() &lt;= endTime) {
  
                  double randomNumber = random.nextDouble() * 100.0;
  
                  final String id = generateRandomId(random);
  
                  ICassandraClientDao clientDao = ClientFactory.getInstance().getDao(clientName);
  
                  clientDao.getAttributes(id, columnsList, columnFamily);
  
              }
          } catch (Exception e) {
  
              }
      }
  
  }
  </code></pre>
  
  <p>And from the above code, I am generating some random id and that id I am using it to pass to my <code>getAttributes</code> dao method.</p>
  
  <p>So from my understanding. Total <code>throughput</code> will be-</p>
  
  <pre><code>total number of request/ total duration the program was run
  </code></pre>
  
  <p>So, in my case, it will be-</p>
  
  <pre><code>total number of id's I have generated/15 minutes
  </code></pre>
  
  <p>Am I right?</p>