jBPM的性能测试

其实也还是hibernate得性能测试.不过为了满足boss的要求,还是写了一个测试.

启动20个线程,每个形成使用JbpmContext生成1000个ProcessInstance,然后遍历每个节点.

测试结果: 每个线程所需时间范围是360 – 420 s

用jconsole看了一下,瓶颈主要在网络读取(jdbc driver的socketread)和连接池等待(waiting available, checkout)上 .

import java.io.FileNotFoundException;
import java.io.IOException;

import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.Log4jConfigurer;
import org.springmodules.workflow.jbpm31.JbpmCallback;
import org.springmodules.workflow.jbpm31.JbpmTemplate;

import com.jpmchase.zpcclass.common.util.SpringUtils;
import com.jpmchase.zpcclass.workflow.service.WorkFlowService;

public class JbpmScalTest {
static {
SpringUtils.initFromClasspath(new String[]{”com/jpmchase/zpcclass/applicationContext*.xml”});
try {
Log4jConfigurer.initLogging(”classpath:com/jpmchase/zpcclass/log4j.properties”);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
WorkFlowService wfs;
private JbpmTemplate jbpmTemplate;
@Before
public void setUp() throws Exception {
wfs = (WorkFlowService) SpringUtils.getBean(”workFlowService”);
jbpmTemplate = (JbpmTemplate) SpringUtils.getBean(”jbpmTemplate”);
}

@After
public void tearDown() throws Exception {
}

public static void main(String[] args) throws Exception {
int threadcount = Integer.parseInt(args[0]);
int cyclecount = Integer.parseInt(args[1]);
String testtype = args[2];
JbpmScalTest test = new JbpmScalTest();
test.setUp();
//test.testScal2();
test.go(threadcount, cyclecount, testtype);
}
class FlowRunner implements Runnable{
String name,unit=”simple”;
long elapse,cycle;
public FlowRunner(String n,long c,String u){
name=n;cycle=c;unit=u;
}
public long getElapse(){return elapse;}
public void run(){
System.out.println(name+” started”);
long start = System.currentTimeMillis();
jbpmTemplate.execute(new JbpmCallback(){
public Object doInJbpm(JbpmContext context) throws JbpmException {
if(unit.equals(”simple”)){
simpleUnit(context);
}else{
fullUnit(context);
}
return null;
}
});
elapse = System.currentTimeMillis() – start;
System.out.println(name+”,”+elapse/1000+”,”+cycle+”,”+unit);
}
public void simpleUnit(JbpmContext context){
ProcessDefinition pd = (ProcessDefinition)context.getGraphSession().findLatestProcessDefinition(”trademgmt”);
for(int i=0;i<cycle;i++){
ProcessInstance pi = new ProcessInstance(pd);
pi.getTaskMgmtInstance().createStartTaskInstance();
}
}
public void fullUnit(JbpmContext context){
ProcessDefinition pd = (ProcessDefinition)context.getGraphSession().findLatestProcessDefinition(”trademgmt”);
for(int i=0;i<cycle;i++){
ProcessInstance pi = new ProcessInstance(pd);
TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();

ti.getToken().signal(”saveInput”);
ti.getToken().signal(”acceptInput”);
ti.getToken().signal(”releaseTrade”);
ti.getToken().signal(”generateObligation”);
ti.getToken().signal(”generateAccountEntry”);
}
}

}
@Test
//2 threads
public void testScal1() throws IOException {
go(20,100,”full”);
go(20,100,”simple”);
System.in.read();
}

private void go(int threadcount,int cyclecount,String testtype)throws IOException {
FlowRunner fr;
Thread t;
for(int i = 0;i<threadcount;i++){
fr = new FlowRunner(”runner”+i,cyclecount,testtype);
t = new Thread(fr);
t.start();
}
}

@Test
//20 threads
public void testScal2() throws IOException {
go(20,1000,”full”);
go(20,1000,”simple”);
System.in.read();
}
}

Comments are closed.