吞吐量主要关注一个特定时间段内应用系统的最大工作量,衡量吞吐量的指标包括以下几点:
给定时间内完成的事务数
每小时批处理系统能完成的作业数量
每小时能完成多少次数据库查询
==========================================================================================
举例:
PigEater:它会模仿一个巨蟒不停的吞食大肥猪的过程,每次吞食在List中添加32M字节来实现这点,每次吞食完成后会睡眠100ms
PigDigester:他会模仿异步消化过程,实现消化后将猪的列表设置为空,这是个很累的过程,因此每次消除后引用这个线程都会睡眠2000ms
============================================================================================================
代码:
import java.util.ArrayList;
import java.util.List;
public class PigInThePython {
public static volatile List pigs=new ArrayList();
public static volatile int PigsEaten=0;
public static final int ENOUGH_PIGS=5000;
static class PigEater extends Thread{
public static void main(String[] args)throws InterruptedException {
new PigEater().start();
new PigDigester().start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
pigs.add(new byte[32*1024*1024]);
if (PigsEaten>ENOUGH_PIGS) {
return;
}
takeANap(100);
}
}
static class PigDigester extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
long start=System.currentTimeMillis();
while (true) {
takeANap(2000);
PigsEaten+=pigs.size();
pigs=new ArrayList();
if (PigsEaten>ENOUGH_PIGS) {
System.out.format("Digested %d pigs in %d ms.%n", PigsEaten, System.currentTimeMillis()-start);
return;
}
}
}
}
static void takeANap(int i) {
// TODO Auto-generated method stub
try {
Thread.sleep(i);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
}