[jbpm-commits] JBoss JBPM SVN: r4127 - jbpm3/branches/jpdl-3.2.2-SOA-4.2/jpdl/jar/src/test/java/org/jbpm/perf.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Mar 3 18:20:30 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-03-03 18:20:30 -0500 (Tue, 03 Mar 2009)
New Revision: 4127
Modified:
jbpm3/branches/jpdl-3.2.2-SOA-4.2/jpdl/jar/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
Log:
JBPM-2043: warm up before measuring job throughput
Modified: jbpm3/branches/jpdl-3.2.2-SOA-4.2/jpdl/jar/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
===================================================================
--- jbpm3/branches/jpdl-3.2.2-SOA-4.2/jpdl/jar/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-03-03 23:19:49 UTC (rev 4126)
+++ jbpm3/branches/jpdl-3.2.2-SOA-4.2/jpdl/jar/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-03-03 23:20:30 UTC (rev 4127)
@@ -21,145 +21,104 @@
*/
package org.jbpm.perf;
-// $Id$
-import java.io.File;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmContext;
-import org.jbpm.JbpmException;
-import org.jbpm.command.CommandService;
-import org.jbpm.command.NewProcessInstanceCommand;
-import org.jbpm.command.SignalCommand;
-import org.jbpm.command.impl.CommandServiceImpl;
+import java.util.concurrent.Semaphore;
+
import org.jbpm.db.AbstractDbTestCase;
-import org.jbpm.graph.def.Action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-import org.jbpm.instantiation.Delegation;
-import org.jbpm.job.ExecuteActionJob;
-import org.jbpm.msg.MessageService;
-import org.jbpm.svc.Services;
/**
- * This tests creates a number of process instances.
- * Every instance has a call to an ActionHandler.
- *
+ * This tests creates a number of process instances. Every instance has a call to an ActionHandler.
* https://jira.jboss.org/jira/browse/JBPM-2043
- *
+ *
* @author mvecera at redhat.com
* @author pmacik at redhat.com
* @author thomas.diesler at jboss.com
* @since 18-Feb-2009
*/
public class SimplePerformanceTest extends AbstractDbTestCase {
- private static final Log log = LogFactory.getLog(SimplePerformanceTest.class);
- private static final String ESB_ASYNC_SIGNAL_ACTION_NAME = "ESB_ASYNC_SIGNAL_ACTION";
- private CommandService commandService = new CommandServiceImpl(getJbpmConfiguration());
- private static final int INSTANCES = 10000;
- private static int count = 1;
- private static AtomicInteger signaled = new AtomicInteger(0);
- private Action signalAction;
- ProcessDefinition processDefinition;
- public void setUp() throws Exception {
- super.setUp();
+ private static final int WARMUP_INSTANCES = 100;
+ private static final int MEASUREMENT_INSTANCES = 1000;
- processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition xmlns='urn:jbpm.org:jpdl-3.1' name='processDefinition1'>" +
- " <start-state name='start'>" +
- " <transition name='to_state' to='end'>" +
- " <action class='" + PerfActionHandler.class.getName() + "'/>" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end'/>" +
- "</process-definition>");
+ private static final Semaphore signalLight = new Semaphore(0);
- final Delegation delegation = new Delegation(AsyncSignalAction.class.getName());
- delegation.setConfigType("constructor");
- signalAction = new Action(delegation);
- signalAction.setName(ESB_ASYNC_SIGNAL_ACTION_NAME);
- processDefinition.addAction(signalAction);
+ private ProcessDefinition processDefinition;
- saveAndReload(processDefinition);
- }
+ public void setUp() throws Exception {
+ super.setUp();
- public void tearDown() throws Exception {
- beginSessionTransaction();
- jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
- super.tearDown();
- }
+ processDefinition = ProcessDefinition.parseXmlString("<process-definition name='perf'>"
+ + " <event type='process-start'>"
+ + " <action class='"
+ + AsyncSignalAction.class.getName()
+ + "' async='true'/>"
+ + " </event>"
+ + " <start-state name='start'>"
+ + " <transition to='end'/>"
+ + " </start-state>"
+ + " <end-state name='end'/>"
+ + "</process-definition>");
+ jbpmContext.deployProcessDefinition(processDefinition);
- public void testAsyncCall() {
- long start = System.currentTimeMillis();
+ newTransaction();
+ startJobExecutor();
+ }
- startJobExecutor();
+ public void tearDown() throws Exception {
+ stopJobExecutor();
- commitAndCloseSession();
+ newTransaction();
+ jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
- for (int i = 0; i < INSTANCES; i++) {
- beginSessionTransaction();
- NewProcessInstanceCommand startCommand = new NewProcessInstanceCommand();
- startCommand.setProcessId(processDefinition.getId());
- startCommand.setProcessName("processDefinition1");
- ProcessInstance pi = (ProcessInstance) commandService.execute(startCommand);
+ super.tearDown();
+ }
- Token token = pi.getRootToken();
- final ExecuteActionJob signalJob = new ExecuteActionJob(token);
+ public void testAsyncCall() {
+ launchProcessInstances(WARMUP_INSTANCES);
- signalJob.setAction(signalAction);
- signalJob.setDueDate(new Date());
- signalJob.setSuspended(token.isSuspended());
+ long startTime = System.currentTimeMillis();
+ launchProcessInstances(MEASUREMENT_INSTANCES);
+ long duration = System.currentTimeMillis() - startTime;
- final MessageService messageService = (MessageService) Services.getCurrentService(Services.SERVICENAME_MESSAGE, true);
- messageService.send(signalJob);
+ System.out.println("=== Test finished processing "
+ + MEASUREMENT_INSTANCES
+ + " instances in "
+ + duration
+ + "ms ===");
+ System.out.println("=== This is "
+ + Math.round(1000f * MEASUREMENT_INSTANCES / duration)
+ + " instances per second ===");
+ }
- commitAndCloseSession();
- }
+ private void launchProcessInstances(int count) {
+ for (int i = 0; i < count; i++) {
+ ProcessInstance pi = new ProcessInstance(processDefinition);
+ jbpmContext.save(pi);
+ newTransaction();
+ }
- while (signaled.get() < INSTANCES) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // no problem, computer's fault
- }
- }
+ commitAndCloseSession();
+ try {
+ signalLight.acquire(count);
+ }
+ catch (InterruptedException e) {
+ fail(getName() + " got interrupted while waiting for process instances to end");
+ }
+ finally {
+ beginSessionTransaction();
+ }
+ }
- stopJobExecutor();
+ public static class AsyncSignalAction implements ActionHandler {
+ private static final long serialVersionUID = -8617329370138396271L;
- long stop = System.currentTimeMillis();
- System.out.println("=== Test finished processing " + INSTANCES + " instances in " + (stop - start) + "ms ===");
- System.out.println("=== This is " + Math.round(1000f * INSTANCES / (stop - start)) + " instances per second ===");
- }
-
- public static class PerfActionHandler implements ActionHandler {
- private static final long serialVersionUID = -2171981067863454024L;
- public void execute(ExecutionContext executionContext) throws Exception {
- //System.out.println(count);
- count++;
- }
- }
-
- private static class AsyncSignalAction implements ActionHandler {
- private static final long serialVersionUID = -8617329370138396271L;
-
- AsyncSignalAction(final String configuration) throws JbpmException {
- }
-
- public void execute(final ExecutionContext executionContext)
- throws Exception {
- final Token token = executionContext.getToken();
- final long tokenId = token.getId();
- final JbpmContext jbpmContext = executionContext.getJbpmContext();
-
- final SignalCommand signalCommand = new SignalCommand(tokenId, null);
- signalCommand.execute(jbpmContext);
-
- signaled.incrementAndGet();
- }
- }
+ public void execute(final ExecutionContext executionContext) throws Exception {
+ executionContext.leaveNode();
+ signalLight.release();
+ }
+ }
}
+
More information about the jbpm-commits
mailing list