Author: alex.guizar(a)jboss.com
Date: 2009-07-04 09:44:35 -0400 (Sat, 04 Jul 2009)
New Revision: 5224
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
Log:
prevent waitForJobs() from doing excessive polling,
made SimplePerformanceTest timeout based on duration of warmup phase
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-07-04
13:41:56 UTC (rev 5223)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-07-04
13:44:35 UTC (rev 5224)
@@ -184,19 +184,48 @@
jobExecutor.start();
}
- protected void waitForJobs(long timeout) {
- long startTime = System.currentTimeMillis();
- while (getNbrOfJobsAvailable() > 0) {
- if (System.currentTimeMillis() - startTime > timeout) {
- fail("test execution exceeded treshold of " + timeout + "
milliseconds");
+ protected void waitForJobs(final long timeout) {
+ final long startTime = System.currentTimeMillis();
+
+ int previousCount = 0;
+ long previousTime = 0L;
+
+ long waitPeriod = 500;
+
+ for (int currentCount; (currentCount = getNbrOfJobsAvailable()) > 0;) {
+ final long currentTime = System.currentTimeMillis();
+
+ final long elapsedTime = currentTime - startTime;
+ if (elapsedTime > timeout) {
+ fail("test execution exceeded threshold of " + timeout + "
ms");
}
- log.debug("waiting for job executor to process more jobs");
+
+ if (currentCount < previousCount) {
+ waitPeriod = currentCount * (currentTime - previousTime) / (previousCount -
currentCount);
+ if (waitPeriod < 500) waitPeriod = 500;
+ }
+ else {
+ waitPeriod <<= 1;
+ }
+
+ if (waitPeriod > 5000) {
+ waitPeriod = 5000;
+ }
+ else {
+ final long remainingTime = timeout - elapsedTime;
+ if (waitPeriod > remainingTime) waitPeriod = remainingTime;
+ }
+
+ log.debug("waiting " + waitPeriod + " ms for " + currentCount +
" jobs to be executed");
try {
- Thread.sleep(500);
+ Thread.sleep(waitPeriod);
}
catch (InterruptedException e) {
- fail("wait for job executor to process more jobs got interrupted");
+ fail("wait for jobs got interrupted");
}
+
+ previousCount = currentCount;
+ previousTime = currentTime;
}
}
@@ -216,14 +245,9 @@
}
private int getNbrOfJobsAvailable(Session session) {
- int nbrOfJobsAvailable = 0;
Number jobs = (Number) session.createQuery("select count(*) from
org.jbpm.job.Job")
.uniqueResult();
- log.debug("there are " + jobs + " jobs in the database");
- if (jobs != null) {
- nbrOfJobsAvailable = jobs.intValue();
- }
- return nbrOfJobsAvailable;
+ return jobs.intValue();
}
protected int getTimerCount() {
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-07-04
13:41:56 UTC (rev 5223)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-07-04
13:44:35 UTC (rev 5224)
@@ -37,7 +37,7 @@
public class SimplePerformanceTest extends AbstractDbTestCase {
private static final int WARMUP_INSTANCES = 100;
- private static final int MEASUREMENT_INSTANCES = 1000;
+ private static final int MEASURED_INSTANCES = 1000;
private static final long TIMEOUT = 5 * 60 * 1000;
private ProcessDefinition processDefinition;
@@ -60,20 +60,18 @@
}
public void testAsyncCall() {
+ long firstTime = System.currentTimeMillis();
launchProcessInstances(WARMUP_INSTANCES);
+ processJobs(TIMEOUT);
- long startTime = System.currentTimeMillis();
- launchProcessInstances(MEASUREMENT_INSTANCES);
- long duration = (System.currentTimeMillis() - startTime) / 1000;
+ long secondTime = System.currentTimeMillis();
+ launchProcessInstances(MEASURED_INSTANCES);
+ processJobs((secondTime - firstTime) * MEASURED_INSTANCES / WARMUP_INSTANCES);
- System.out.println("=== Test finished processing " +
- MEASUREMENT_INSTANCES +
- " instances in " +
- duration +
- " seconds ===");
- System.out.println("=== This is " +
- (MEASUREMENT_INSTANCES / duration) +
- " instances per second ===");
+ long duration = (System.currentTimeMillis() - secondTime) / 1000;
+ System.out.println("==> Processed " +
+ (MEASURED_INSTANCES / duration) +
+ " instances per second <==");
}
private void launchProcessInstances(int count) {
@@ -83,7 +81,5 @@
processInstance.signal();
jbpmContext.save(processInstance);
}
-
- processJobs(TIMEOUT);
}
}
Show replies by date