[jbpm-commits] JBoss JBPM SVN: r3562 - in jbpm4/trunk/modules/test-load/src/test: resources and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sun Dec 28 13:27:14 EST 2008
Author: tom.baeyens at jboss.com
Date: 2008-12-28 13:27:11 -0500 (Sun, 28 Dec 2008)
New Revision: 3562
Added:
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/LoadTestCase.java
Removed:
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTestCase.java
Modified:
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/Automatic.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/MessageProcessingTest.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ProcessExecutionTest.java
jbpm4/trunk/modules/test-load/src/test/resources/logging.properties
Log:
load testing fine tuning
Modified: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/Automatic.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/Automatic.java 2008-12-27 13:44:33 UTC (rev 3561)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/Automatic.java 2008-12-28 18:27:11 UTC (rev 3562)
@@ -26,7 +26,6 @@
*/
public class Automatic {
-
public void doNothing() {
}
}
Deleted: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTestCase.java 2008-12-27 13:44:33 UTC (rev 3561)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTestCase.java 2008-12-28 18:27:11 UTC (rev 3562)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.test.load;
-
-import java.util.Date;
-
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.jbpm.cmd.Command;
-import org.jbpm.cmd.CommandService;
-import org.jbpm.env.Environment;
-import org.jbpm.pvm.internal.job.JobImpl;
-import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
-import org.jbpm.test.DbTestCase;
-
-
-/**
- * @author Tom Baeyens
- */
-public class JobExecutorTestCase extends DbTestCase {
-
- static long checkInterval = 5000;
-
- static String jobsAvailableQueryText =
- "select count(*) "+
- "from "+JobImpl.class.getName()+" as job "+
- "where ( (job.dueDate is null) or (job.dueDate <= :now) ) "+
- " and ( job.retries > 0 )";
-
- protected CommandService commandService;
- protected JobExecutor jobExecutor;
-
- protected void setUp() throws Exception {
- super.setUp();
-
- commandService = processEngine.get(CommandService.class);
- jobExecutor = processEngine.get(JobExecutor.class);
- }
-
- protected void waitTillNoMoreMessages(JobExecutor jobExecutor) throws Exception {
- boolean jobsAvailable = true;
- while (jobsAvailable) {
- log.debug("going to sleep for " + checkInterval + " millis, waiting for the job executor to process more jobs");
- Thread.sleep(checkInterval);
- jobsAvailable = areJobsAvailable();
- logStatus();
- }
- }
-
- public void logStatus() {
- }
-
- public boolean areJobsAvailable() {
- return commandService.execute(new Command<Boolean>() {
- public Boolean execute(Environment environment) {
- Session session = environment.get(Session.class);
-
- Query query = session.createQuery(jobsAvailableQueryText);
- query.setDate("now", new Date());
-
- Long jobs = (Long) query.uniqueResult();
-
- if (jobs.longValue()>0) {
- log.debug("found "+jobs+" more jobs to process");
- return true;
- }
- log.debug("no more jobs to process");
-
- return false;
- }
- });
- }
-
-}
Added: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/LoadTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/LoadTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/LoadTestCase.java 2008-12-28 18:27:11 UTC (rev 3562)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.load;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Date;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.cmd.Command;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.job.JobImpl;
+import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
+import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class LoadTestCase extends DbTestCase {
+
+ static final long SECOND = 1000;
+ static final long MINUTE = 60 * SECOND;
+ static final long HOUR = 60 * MINUTE;
+
+ static long checkInterval = 200;
+
+ static String jobsAvailableQueryText =
+ "select count(*) "+
+ "from "+JobImpl.class.getName()+" as job "+
+ "where ( (job.dueDate is null) or (job.dueDate <= :now) ) "+
+ " and ( job.retries > 0 )";
+
+ static boolean measureMemory = true;
+
+ protected CommandService commandService;
+ protected JobExecutor jobExecutor;
+ long startTime = -1;
+ long stopTime = -1;
+ PrintWriter logFileWriter;
+
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ if (measureMemory) {
+ openMemoryLogFile();
+ }
+
+ commandService = processEngine.get(CommandService.class);
+ jobExecutor = processEngine.get(JobExecutor.class);
+ }
+
+ protected void tearDown() throws Exception {
+ if (measureMemory) {
+ closeMemoryLogFile();
+ }
+
+ super.tearDown();
+ }
+
+ public void startMeasuringTime() {
+ if (stopTime==-1) {
+ startTime = System.currentTimeMillis();
+ } else {
+ startTime = startTime + (System.currentTimeMillis() - stopTime);
+ stopTime = -1;
+ }
+ }
+
+ public void stopMeasuringTime() {
+ stopTime = System.currentTimeMillis();
+ }
+
+ protected void openMemoryLogFile() throws Exception {
+ String testClass = ReflectUtil.getUnqualifiedClassName(getClass());
+ logFileWriter = new PrintWriter(new File("target/"+testClass +".txt"));
+ logColumnTitles();
+ }
+
+ protected void logColumnTitles() {
+ logFileWriter.println("Used Memory");
+ }
+
+ protected void closeMemoryLogFile() {
+ logFileWriter.close();
+ }
+
+ protected void logStatus() {
+ logFileWriter.println(getUsedMemory());
+ }
+
+ protected long getUsedMemory() {
+ Runtime runtime = Runtime.getRuntime();
+ long total = runtime.totalMemory();
+ long free = runtime.freeMemory();
+ long used = total - free;
+ return used;
+ }
+
+ protected void waitTillNoMoreMessages(JobExecutor jobExecutor) throws Exception {
+ boolean jobsAvailable = true;
+ while (jobsAvailable) {
+ log.debug("going to sleep for " + checkInterval + " millis, waiting for the job executor to process more jobs");
+ Thread.sleep(checkInterval);
+ jobsAvailable = areJobsAvailable();
+ logStatus();
+ }
+ }
+
+ public boolean areJobsAvailable() {
+ return commandService.execute(new Command<Boolean>() {
+ public Boolean execute(Environment environment) {
+ Session session = environment.get(Session.class);
+
+ Query query = session.createQuery(jobsAvailableQueryText);
+ query.setDate("now", new Date());
+
+ Long jobs = (Long) query.uniqueResult();
+
+ if (jobs.longValue()>0) {
+ log.debug("found "+jobs+" more jobs to process");
+ return true;
+ }
+ log.debug("no more jobs to process");
+
+ return false;
+ }
+ });
+ }
+
+ public String getMeasuredTime() {
+ long stop = stopTime!=-1 ? stopTime : System.currentTimeMillis();
+ long diff = stop - startTime;
+
+ long hours = diff / HOUR;
+ diff = diff - (hours * HOUR);
+
+ long minutes = diff / MINUTE;
+ diff = diff - (minutes * MINUTE);
+
+ long seconds = diff / SECOND;
+
+ StringBuffer text = new StringBuffer();
+ if (hours!=0) {
+ text.append(hours+"h");
+ }
+ text.append(minutes);
+ text.append("'");
+ text.append(seconds);
+ text.append("\"");
+
+ // long millis = diff - (seconds * SECOND);
+ // text.append(","+millis);
+
+ return text.toString();
+ }
+}
Modified: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/MessageProcessingTest.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/MessageProcessingTest.java 2008-12-27 13:44:33 UTC (rev 3561)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/MessageProcessingTest.java 2008-12-28 18:27:11 UTC (rev 3562)
@@ -21,14 +21,11 @@
*/
package org.jbpm.test.load;
-import java.io.File;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.jbpm.cmd.Command;
-import org.jbpm.cmd.CommandService;
import org.jbpm.env.Environment;
import org.jbpm.job.Message;
import org.jbpm.log.Log;
@@ -42,78 +39,41 @@
* @author Tom Baeyens
* @author Guillaume Porcher
*/
-public class MessageProcessingTest extends JobExecutorTestCase {
+public class MessageProcessingTest extends LoadTestCase {
private static final Log log = Log.getLog(MessageProcessingTest.class.getName());
- static long nbrOfTestMessages = 10000; // nbrOfTestMessages must be dividable by insertGroupSize
- static long insertGroupSize = 50;
+ static long nbrOfTestMessages = 50000; // nbrOfTestMessages must be dividable by insertGroupSize
+ static long insertGroupSize = 100;
- static final long SECOND = 1000;
- static final long MINUTE = 60 * SECOND;
- static final long HOUR = 60 * MINUTE;
-
- static boolean measureMemory = true;
-
- static long timeoutMillis = 30 * MINUTE; // 10 minutes
- static long checkInterval = 5000;
-
- static long start = -1;
static int commentsAdded = 0;
public static synchronized void commentAdded() {
commentsAdded++;
}
- CommandService commandService;
- PrintWriter memoryWriter;
-
public void setUp() throws Exception {
super.setUp();
if ( (nbrOfTestMessages % insertGroupSize) != 0 ) {
fail("nbrOfTestMessages ("+nbrOfTestMessages+") is not dividable by insertGroupSize ("+insertGroupSize+")");
}
-
- if (measureMemory) {
- openMemoryLogFile();
- }
-
- commandService = processEngine.get(CommandService.class);
}
- protected void tearDown() throws Exception {
- if (measureMemory) {
- closeMemoryLogFile();
- }
-
- super.tearDown();
+ protected void logColumnTitles() {
+ logFileWriter.println("Used Memory\tProcessed Messages\tTime");
}
-
- void openMemoryLogFile() throws Exception {
- memoryWriter = new PrintWriter(new File("target/memory.txt"));
- }
-
- void closeMemoryLogFile() {
- memoryWriter.close();
- }
-
public void logStatus() {
- Runtime runtime = Runtime.getRuntime();
- long total = runtime.totalMemory();
- long free = runtime.freeMemory();
- long used = total - free;
- memoryWriter.println(used);
-
- log.info(commentsAdded+" msgs in "+formatDuration(start, System.currentTimeMillis()));
+ String measuredTime = getMeasuredTime();
+ logFileWriter.println(getUsedMemory()+"\t"+commentsAdded+"\t"+measuredTime);
+ logFileWriter.flush();
+ log.info(commentsAdded+" msgs in "+measuredTime);
}
-
+
public void testMessageProcessing() throws Exception {
JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
- long stop = -1;
-
try {
int messageIndex = 0;
// insert ${nbrOfTestMessages} messages...
@@ -132,7 +92,7 @@
log.info("added "+messageIndex+" messages");
}
- start = System.currentTimeMillis();
+ startMeasuringTime();
jobExecutor.start();
@@ -140,12 +100,12 @@
waitTillNoMoreMessages(jobExecutor);
} finally {
- stop = System.currentTimeMillis();
+ stopMeasuringTime();
jobExecutor.stop(true);
}
- log.info("processing "+nbrOfTestMessages+" messages took "+formatDuration(start, stop));
+ log.info("processing "+nbrOfTestMessages+" messages took "+getMeasuredTime());
List<Integer> processedMessageNumbers = commandService.execute(new Command<List<Integer>>() {
public List<Integer> execute(Environment environment) {
@@ -167,33 +127,4 @@
}
}
- // helper methods ///////////////////////////////////////////////////////////
-
- public static String formatDuration(long start, long stop) {
- long diff = stop-start;
-
- long hours = diff / HOUR;
- diff = diff - (hours * HOUR);
-
- long minutes = diff / MINUTE;
- diff = diff - (minutes * MINUTE);
-
- long seconds = diff / SECOND;
- diff = diff - (seconds * SECOND);
-
- StringBuffer text = new StringBuffer();
- if (hours!=0) {
- text.append(hours+" hours, ");
- }
- if (minutes!=0) {
- text.append(minutes+" minutes, ");
- }
- if (seconds!=0) {
- text.append(seconds+" seconds and ");
- }
- if (diff!=0) {
- text.append(diff+" ms");
- }
- return text.toString();
- }
}
Modified: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ProcessExecutionTest.java
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ProcessExecutionTest.java 2008-12-27 13:44:33 UTC (rev 3561)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ProcessExecutionTest.java 2008-12-28 18:27:11 UTC (rev 3562)
@@ -26,24 +26,38 @@
import org.jbpm.Execution;
import org.jbpm.log.Log;
-import org.jbpm.test.DbTestCase;
/**
* @author Tom Baeyens
*/
-public class ProcessExecutionTest extends DbTestCase {
+public class ProcessExecutionTest extends LoadTestCase {
private static Log log = Log.getLog(ProcessExecutionTest.class.getName());
- static int processes = 500;
+ static int processes = 50000;
static int threads = 10;
Throwable exception;
+ int finished;
+ public void logStatus() {
+ String measuredTime = getMeasuredTime();
+ logFileWriter.println(getUsedMemory()+"\t"+finished+"\t"+measuredTime);
+ logFileWriter.flush();
+ log.info(finished+" executions in "+measuredTime);
+ }
+
+ protected void logColumnTitles() {
+ logFileWriter.println("Used Memory\tFinished Executions\tTime");
+ logFileWriter.flush();
+ }
+
public void testExecuteProcesses() throws Exception {
deployJpdlResource("org/jbpm/test/load/process.jpdl.xml");
+ startMeasuringTime();
+
List<Thread> threadList = new ArrayList<Thread>();
for (int i=0; i<threads; i++) {
Thread thread = new ProcessExecutor();
@@ -51,11 +65,15 @@
threadList.add(thread);
}
+
for (Thread thread: threadList) {
- try {
- thread.join();
- } catch (InterruptedException e) {
- log.info(e.toString());
+ while (thread.isAlive()) {
+ try {
+ thread.join(checkInterval);
+ } catch (InterruptedException e) {
+ log.info(e.toString());
+ }
+ logStatus();
}
if (exception!=null) {
break;
@@ -64,6 +82,8 @@
if (exception!=null) {
throw new Exception("thread threw: "+exception.getMessage(), exception);
+ } else {
+ log.info(finished+" executions in "+getMeasuredTime());
}
}
@@ -83,8 +103,11 @@
String executionId = execution.getId();
execution = executionService.signalExecutionById(executionId);
assertTrue(execution.isEnded());
+ processFinished();
}
}
-
+ public synchronized void processFinished() {
+ finished++;
+ }
}
Modified: jbpm4/trunk/modules/test-load/src/test/resources/logging.properties
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/resources/logging.properties 2008-12-27 13:44:33 UTC (rev 3561)
+++ jbpm4/trunk/modules/test-load/src/test/resources/logging.properties 2008-12-28 18:27:11 UTC (rev 3562)
@@ -15,8 +15,8 @@
# com.xyz.foo.level = SEVERE
org.jbpm.level=INFO
-org.jbpm.pvm.internal.model.level=FINE
-org.jbpm.pvm.internal.model.op.level=FINE
+# org.jbpm.pvm.internal.model.level=FINE
+# org.jbpm.pvm.internal.model.op.level=FINE
# org.jbpm.pvm.internal.tx.level=FINE
# org.jbpm.pvm.internal.wire.level=FINE
# org.jbpm.pvm.internal.util.level=FINE
More information about the jbpm-commits
mailing list