posted on 2007-10-12 13:01
dennis 阅读(995)
评论(9)
上午测试了下并发情况下的表现,测试场景:一个有20个节点,包括选择、顺序、并行路由的流程,所有节点都设置为自动执行,1000个线程并发启动案例,也就是这个流程同时有1000个案例在跑,全部跑完结果差强人意,比单线程慢了接近30倍。仔细调整了算法和加锁粒度,尽管整体性能有所提高,但是多线程和单线程间执行的差距仍然没有多大变化,性能瓶颈还是在核心的调度算法上,还需要分析下。测试程序如下:
package net.rubyeye.insect.workflow.test;
import java.util.arraylist;
import java.util.list;
import java.util.concurrent.cyclicbarrier;
import net.rubyeye.insect.workflow.place;
import net.rubyeye.insect.workflow.token;
import net.rubyeye.insect.workflow.transition;
import net.rubyeye.insect.workflow.workflow;
import net.rubyeye.insect.workflow.workflowmanager;
import net.rubyeye.insect.workflow.basic.basicworkflowmanager;
import net.rubyeye.insect.workflow.comm.transitiontype;
import net.rubyeye.insect.workflow.config.defaultconfiguration;
import junit.framework.testcase;
public class compositeprocesstest extends testcase {
private workflowmanager wm;
workflow composite;
private cyclicbarrier barrier;
private static final int total = 1000;
@override
protected void setup() throws exception {
this.barrier = new cyclicbarrier(total 1);
wm = new basicworkflowmanager();
wm.setconfiguration(new defaultconfiguration());
workflow sequence = wm.getworkflow("sequence");
workflow concurrency = wm.getworkflow("concurrency");
workflow choose = wm.getworkflow("choose");
// 组合流程
composite = new workflow();
composite.setname("composite");
composite.setid(100);
wm.saveworkflow(composite);
// 修改开始结束节点的输入输出库所
sequence.getend().settype(transitiontype.normal);
sequence.getend().setoutputs(concurrency.getstart().getinputs());
concurrency.getend().settype(transitiontype.normal);
concurrency.getend().setoutputs(choose.getstart().getinputs());
composite.setstart(sequence.getstart());
composite.setend(choose.getend());
list<transition> transitions = new arraylist<transition>();
transitions.addall(sequence.gettransitions());
transitions.addall(concurrency.gettransitions());
transitions.addall(choose.gettransitions());
composite.settransitions(transitions);
}
public void testconcurrencycompositeprocesss() throws exception {
for (int i = 0; i < total; i) {
new flowthread().start();
}
barrier.await();
long start = system.currenttimemillis();
barrier.await();
long end = system.currenttimemillis();
system.out.println("创建" total "个流程并发运行完毕\n花费时间:" (end - start)
/ 1000.0 "秒");
for (transition transition : composite.gettransitions()) {
system.out.println(transition.getname() " "
transition.isenable());
for (place place : transition.getoutputs()) {
system.out.println("place " place.getid() " "
place.gettokens().size());
}
}
}
public void testcompositeprocesss() throws exception {
long start = system.currenttimemillis();
for (int i = 0; i < total; i) {
token token1 = wm.startworkflow("composite");
token1.setattribute("name", "dennis");
token1.setattribute("num", 21);
wm.doaction(token1.getid());
asserttrue(token1.isfinished());
}
long end = system.currenttimemillis();
system.out.println("创建" total "个流程运行完毕\n花费时间:" (end - start)
/ 1000.0 "秒");
}
class flowthread extends thread {
@override
public void run() {
try {
barrier.await();
// wm = new basicworkflowmanager();
token token1 = wm.startworkflow("composite");
token1.setattribute("name", "dennis");
token1.setattribute("num", 21);
wm.doaction(token1.getid());
asserttrue(token1.isfinished());
barrier.await();
} catch (exception e) {
throw new runtimeexception(e);
}
}
}
}