Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrez committed Jul 17, 2015
1 parent 6842a1c commit 53fddd5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 70 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<version>1.0</version>

<properties>
<activiti.version>5.17.0</activiti.version>
<activiti.version>6.0.0-SNAPSHOT</activiti.version>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>

Expand Down Expand Up @@ -43,6 +43,11 @@
<artifactId>postgresql</artifactId>
<version>9.0-801.jdbc4</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
Expand Down
48 changes: 5 additions & 43 deletions src/main/java/be/jorambarrez/activiti/benchmark/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import be.jorambarrez.activiti.benchmark.execution.ProcessEngineHolder;
import be.jorambarrez.activiti.benchmark.output.BenchmarkOuput;
import be.jorambarrez.activiti.benchmark.output.BenchmarkResult;
import be.jorambarrez.activiti.benchmark.util.Utils;

import java.util.ArrayList;
import java.util.Date;
Expand All @@ -19,7 +20,7 @@
public class Benchmark {

public static String[] PROCESSES = {
"process01",
"process01",
"process02",
"process03",
"process04",
Expand All @@ -37,7 +38,6 @@ public class Benchmark {
public static String HISTORY_VALUE;
public static boolean HISTORY_ENABLED;
public static String CONFIGURATION_VALUE;
public static boolean FIXED_NR_THREADPOOLS;

private static List<BenchmarkResult> fixedPoolSequentialResults = new ArrayList<BenchmarkResult>();
private static List<BenchmarkResult> fixedPoolRandomResults = new ArrayList<BenchmarkResult>();
Expand All @@ -56,25 +56,15 @@ public static void main(String[] args) throws Exception {
int nrOfExecutions = Integer.valueOf(args[0]);
maxNrOfThreadsInThreadPool = Integer.valueOf(args[1]);

if (FIXED_NR_THREADPOOLS) {
executeFixedThreadPoolBenchmark(nrOfExecutions, maxNrOfThreadsInThreadPool);
} else {
executeBenchmarks(nrOfExecutions, maxNrOfThreadsInThreadPool);
}
executeBenchmarks(nrOfExecutions, maxNrOfThreadsInThreadPool);

System.out.println("Benchmark completed. Ran for "
+ ((System.currentTimeMillis() - start) / 1000L) + " seconds");
System.out.println("Benchmark completed. Ran for " + ((System.currentTimeMillis() - start) / 1000L) + " seconds");
}

private static void executeBenchmarks(int nrOfProcessExecutions, int maxNrOfThreadsInThreadPool) {

// Deploy test processes
System.out.println("Deploying test processes");
for (String process : PROCESSES) {
ProcessEngineHolder.getInstance().getRepositoryService().createDeployment()
.addClasspathResource(process + ".bpmn20.xml").deploy();
}
System.out.println("Finished deploying test processes");
Utils.cleanAndRedeployTestProcesses();

// Single thread benchmark
System.out.println(new Date() + " - benchmarking with one thread.");
Expand Down Expand Up @@ -111,29 +101,6 @@ private static void writeHtmlReport() {
output.writeOut();
}

private static void executeFixedThreadPoolBenchmark(int nrOfProcessExecutions, int nrOfThreadInThreadPool) {

// Deploy test processes
System.out.println("Deploying test processes");
for (String process : PROCESSES) {
ProcessEngineHolder.getInstance().getRepositoryService().createDeployment()
.addClasspathResource(process + ".bpmn20.xml").deploy();
}
System.out.println("Finished deploying test processes");

System.out.println(new Date() + " - benchmarking with fixed threadpool of " + nrOfThreadInThreadPool + " threads.");
BenchmarkExecution fixedPoolBenchMark = new FixedThreadPoolBenchmarkExecution(nrOfThreadInThreadPool, PROCESSES);
fixedPoolSequentialResults.add(fixedPoolBenchMark.sequentialExecution(PROCESSES, nrOfProcessExecutions, HISTORY_ENABLED));
fixedPoolRandomResults.add(fixedPoolBenchMark.randomExecution(PROCESSES, nrOfProcessExecutions, HISTORY_ENABLED));

// Output
BenchmarkOuput output = new BenchmarkOuput();
output.start("Activiti " + ProcessEngineHolder.getInstance().VERSION + " basic benchmark results - FIXED number of threadpools");
output.addBenchmarkResult("Fixed thread pool (" + nrOfThreadInThreadPool + "threads), sequential", fixedPoolSequentialResults.get(0));
output.addBenchmarkResult("Fixed thread pool (" + nrOfThreadInThreadPool + "threads), randomized", fixedPoolRandomResults.get(0));
output.writeOut();
}

/**
* Validates the commandline arguments.
*
Expand Down Expand Up @@ -187,11 +154,6 @@ private static boolean readAndValidateParams(String[] args) {
return false;
}

if (System.getProperties().containsKey("fixedNrOfThreadPools")) {
FIXED_NR_THREADPOOLS = true;
System.out.println("FIXED number of threadpools enabled");
}

try {
Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ public BenchmarkResult sequentialExecution(String[] processes, int nrOfProcessEx
BenchmarkResult result = new BenchmarkResult(1);

for (String process : processes) {

System.out.println(new Date() + " : [SEQ]Starting " + nrOfProcessExecutions + " of process " + process);
long allProcessesStart = System.currentTimeMillis();

for (int i = 0; i < nrOfProcessExecutions; i++) {
ExecuteProcessRunnable executeProcessRunnable = new ExecuteProcessRunnable(process, ProcessEngineHolder.getInstance());
executeProcessRunnable.run();
result.addProcessInstanceMeasurement(process, executeProcessRunnable.getDuration());
if (i%100 == 0) {
System.out.println("Finished " + i + "/" + nrOfProcessExecutions);
}
}

long allProcessesEnd = System.currentTimeMillis();
System.out.println("Execution time = " + (allProcessesEnd - allProcessesStart) + " ms");
result.addTotalTimeMeasurementForProcess(process, nrOfProcessExecutions, allProcessesEnd - allProcessesStart);
}

Expand Down Expand Up @@ -97,30 +101,30 @@ public BenchmarkResult randomExecution(String[] processes, int totalNrOfExecutio


protected void cleanAndDeploy() {

System.out.println(new Date() + " : Recreating DB schema");

((ProcessEngineImpl) ProcessEngineHolder.getInstance()).getProcessEngineConfiguration()
// .getCommandExecutorTxRequiresNew() // For 5.10
.getCommandExecutor()
.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);
dbSqlSession.dbSchemaDrop();
dbSqlSession.dbSchemaCreate();
return null;
}
});
public Object execute(CommandContext commandContext) {
DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);
dbSqlSession.dbSchemaDrop();
dbSqlSession.dbSchemaCreate();
return null;
}
});

System.out.println("Rebooting process engine");
ProcessEngineHolder.rebootProcessEngine();

System.out.println("Redeploying test processes");
for (String process : Benchmark.PROCESSES) {
ProcessEngineHolder.getInstance().getRepositoryService().createDeployment()
.addClasspathResource(process + ".bpmn20.xml").deploy();
}

try {
Thread.sleep(10000L);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -154,17 +158,17 @@ private long countNrOfEndedProcesses() {
}

static class DeleteHistoricProcessInstancesRunnable implements Runnable {

private HistoryService historyService;
private long start;
private long pageSize;

public DeleteHistoricProcessInstancesRunnable(HistoryService historyService, long start, long pageSize) {
this.historyService = historyService;
this.start = start;
this.pageSize = pageSize;
}

public void run() {
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().listPage((int)start, (int)pageSize);
int counter = 0;
Expand All @@ -180,21 +184,21 @@ public void run() {
}
System.out.println(new Date() + " : Deleted " + counter + " historic process instances");
}

}

static class DeleteProcessInstancesRunnable implements Runnable {

private RuntimeService runtimeService;
private long start;
private long pageSize;

public DeleteProcessInstancesRunnable(RuntimeService runtimeService, long start, long pageSize) {
this.runtimeService = runtimeService;
this.start = start;
this.pageSize = pageSize;
}

public void run() {
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().listPage((int)start, (int)pageSize);
int counter = 0;
Expand All @@ -204,7 +208,7 @@ public void run() {
}
System.out.print(new Date() + " : Deleted " + counter + " process instances");
}

}

}
20 changes: 20 additions & 0 deletions src/main/java/be/jorambarrez/activiti/benchmark/util/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package be.jorambarrez.activiti.benchmark.util;

import be.jorambarrez.activiti.benchmark.Benchmark;
import be.jorambarrez.activiti.benchmark.execution.ProcessEngineHolder;
import org.activiti.engine.repository.Deployment;

import java.util.Random;

public class Utils {
Expand Down Expand Up @@ -27,5 +31,21 @@ public static String toString(String[] strings) {
strb.deleteCharAt(strb.length() - 1);
return strb.toString();
}

public static void cleanAndRedeployTestProcesses() {

System.out.print("Removing deployments... ");
for (Deployment deployment : ProcessEngineHolder.getInstance().getRepositoryService().createDeploymentQuery().list()) {
ProcessEngineHolder.getInstance().getRepositoryService().deleteDeployment(deployment.getId(), true);
}

System.out.print("Finished cleaning up. Deploying test processes... ");
for (String process : Benchmark.PROCESSES) {
ProcessEngineHolder.getInstance().getRepositoryService().createDeployment()
.addClasspathResource(process + ".bpmn20.xml").deploy();
}
System.out.println("Finished deploying test processes");

}

}
13 changes: 9 additions & 4 deletions src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
handlers = java.util.logging.ConsoleHandler
.level = WARNING
java.util.logging.ConsoleHandler.level=WARNING
java.util.logging.ConsoleHandler.formatter=org.activiti.pvm.impl.util.LogUtil$LogFormatter
log4j.rootLogger=WARN, CA

# ConsoleAppender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n


log4j.logger.org.apache.ibatis.level=WARN
log4j.logger.javax.activation.level=WARN
2 changes: 1 addition & 1 deletion src/main/resources/spring-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="databaseSchemaUpdate" value="drop-create"/>
<property name="jobExecutorActivate" value="false"/>
<property name="history" value="${history}" />

Expand Down

0 comments on commit 53fddd5

Please sign in to comment.