我正在bench marking
处理我的一些客户端代码。现在我试图找出如何从我的Multithreading
代码计算吞吐量 -
我正在运行我的程序20 threads
。并且每个线程都会运行15 minutes
,所以所有的20 threads will run for 15 minutes
.
下面是我的代码-
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 < 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);
}
}
下面是我实现的类Runnable interface
-
class CassandraReadTask implements Runnable {
public void run() {
try {
while (System.currentTimeMillis() <= 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) {
}
}
}
从上面的代码中,我生成了一些随机 id,并且我使用它来传递给我的getAttributes
dao 方法。
所以根据我的理解。总计throughput
将是-
total number of request/ total duration the program was run
所以,就我而言,它将是——
total number of id's I have generated/15 minutes
我对吗?