Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrez committed Jul 6, 2015
1 parent 90b6bdc commit 6842a1c
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 212 deletions.
6 changes: 5 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
./build.sh

cd target

mysql -u alfresco -palfresco -e "DROP SCHEMA benchmark"
mysql -u alfresco -palfresco -e "CREATE SCHEMA benchmark DEFAULT CHARACTER SET utf8 COLLATE utf8_bin"
java -Xms512M -Xmx2048M -DjdbcUrl=jdbc:mysql://localhost:3306/benchmark?characterEncoding=UTF-8 -DjdbcUsername=alfresco -DjdbcPassword=alfresco -DjdbcDriver=com.mysql.jdbc.Driver -Dhistory=none -Dconfig=spring -jar activiti-basic-benchmark.jar 500 8

java -Xms512M -Xmx2048M -DjdbcUrl=jdbc:mysql://localhost:3306/benchmark?characterEncoding=UTF-8 -DjdbcUsername=alfresco -DjdbcPassword=alfresco -DjdbcDriver=com.mysql.jdbc.Driver -Dhistory=audit -Dconfig=spring -jar activiti-basic-benchmark.jar 2500 10
64 changes: 40 additions & 24 deletions src/main/java/be/jorambarrez/activiti/benchmark/Benchmark.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package be.jorambarrez.activiti.benchmark;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import be.jorambarrez.activiti.benchmark.execution.BasicBenchmarkExecution;
import be.jorambarrez.activiti.benchmark.execution.BenchmarkExecution;
import be.jorambarrez.activiti.benchmark.execution.FixedThreadPoolBenchmarkExecution;
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.profiling.ProfilingInterceptor;
import be.jorambarrez.activiti.benchmark.profiling.ProfilingLogParser;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* Main class that contains the logic to execute the benchmark.
Expand All @@ -29,15 +27,17 @@ public class Benchmark {
"process-usertask-01",
"process-usertask-02",
"process-usertask-03",
"process-multi-instance-01"
"process-multi-instance-01",
"process-variables-servicetask01",
"process-variables-servicetask02"
};

private static int maxNrOfThreadsInThreadPool;

public static String HISTORY_VALUE;
public static boolean HISTORY_ENABLED;
public static String CONFIGURATION_VALUE;
public static boolean PROFILING_ENABLED;
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,20 +56,10 @@ public static void main(String[] args) throws Exception {
int nrOfExecutions = Integer.valueOf(args[0]);
maxNrOfThreadsInThreadPool = Integer.valueOf(args[1]);

executeBenchmarks(nrOfExecutions, maxNrOfThreadsInThreadPool);
writeHtmlReport();

if (PROFILING_ENABLED) {
System.out.println();
System.out.println("Generating profile report");
System.out.println();

// flushing writer and sleeping a bit, just to be sure
ProfilingInterceptor.fileWriter.flush();
Thread.sleep(5000L);

ProfilingLogParser profilingLogParser = new ProfilingLogParser();
profilingLogParser.execute();
if (FIXED_NR_THREADPOOLS) {
executeFixedThreadPoolBenchmark(nrOfExecutions, maxNrOfThreadsInThreadPool);
} else {
executeBenchmarks(nrOfExecutions, maxNrOfThreadsInThreadPool);
}

System.out.println("Benchmark completed. Ran for "
Expand Down Expand Up @@ -100,6 +90,8 @@ private static void executeBenchmarks(int nrOfProcessExecutions, int maxNrOfThre
fixedPoolSequentialResults.add(fixedPoolBenchMark.sequentialExecution(PROCESSES, nrOfProcessExecutions, HISTORY_ENABLED));
fixedPoolRandomResults.add(fixedPoolBenchMark.randomExecution(PROCESSES, nrOfProcessExecutions, HISTORY_ENABLED));
}

writeHtmlReport();
}

private static void writeHtmlReport() {
Expand All @@ -119,6 +111,29 @@ 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 @@ -172,8 +187,9 @@ private static boolean readAndValidateParams(String[] args) {
return false;
}

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

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GenerateRandomValueActivity implements JavaDelegate {

private static Random random = new Random();

public void execute(DelegateExecution execution) throws Exception {
public void execute(DelegateExecution execution) {
Integer value = random.nextInt(10);
execution.setVariable("var", value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package be.jorambarrez.activiti.benchmark.delegate;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.impl.el.Expression;

public class GenerateVariablesDelegate implements JavaDelegate {

private Expression numberOfVariablesString;

@Override
public void execute(DelegateExecution delegateExecution) {
int numberOfVariables = Integer.valueOf(numberOfVariablesString.getValue(delegateExecution).toString());
for (int i=0; i<numberOfVariables; i++) {
if (i%2 == 0) {
delegateExecution.setVariable("var" + i, i); // integer
} else {
delegateExecution.setVariable("var" + i, i + ""); // string
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ public BenchmarkResult randomExecution(String[] processes, int totalNrOfExecutio
protected void cleanAndDeploy() {

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

((ProcessEngineImpl) ProcessEngineHolder.getInstance()).getProcessEngineConfiguration()
.getCommandExecutor().execute(new Command<Object>() {
// .getCommandExecutorTxRequiresNew() // For 5.10
.getCommandExecutor()
.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);
dbSqlSession.dbSchemaDrop();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package be.jorambarrez.activiti.benchmark.execution;

import java.util.ArrayList;
import java.util.List;

import be.jorambarrez.activiti.benchmark.Benchmark;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.interceptor.CommandInterceptor;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import be.jorambarrez.activiti.benchmark.Benchmark;
import be.jorambarrez.activiti.benchmark.profiling.ProfilingInterceptor;

public class ProcessEngineHolder {

private static ProcessEngine PROCESS_ENGINE;
Expand All @@ -38,22 +31,10 @@ private static ProcessEngine getProcessEngine() {
System.out.println("url : " + processEngineConfiguration.getJdbcUrl());
System.out.println("driver : " + processEngineConfiguration.getJdbcDriver());

if (Benchmark.PROFILING_ENABLED) {
List<CommandInterceptor> interceptors = new ArrayList<CommandInterceptor>();
interceptors.add(new ProfilingInterceptor());
((ProcessEngineConfigurationImpl) processEngineConfiguration)
.setCustomPreCommandInterceptors(interceptors);
}

return processEngineConfiguration.buildProcessEngine();
} else if (Benchmark.CONFIGURATION_VALUE.equals("spring")) {
System.out.println("Using SPRING config");
APP_CTX = new ClassPathXmlApplicationContext("spring-context.xml");

if (Benchmark.PROFILING_ENABLED) {
throw new RuntimeException("Profiling is currently only possible in default configuration");
}

return APP_CTX.getBean(ProcessEngine.class);
}
throw new RuntimeException("Invalid config: only 'default' and 'spring' are supported");
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6842a1c

Please sign in to comment.