@Test
public void should_run_drl_not_threaded()
{
for (int r = 0; r < RUNS; r++)
{
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
KieSession kieSession = kieBase.newKieSession();
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
}
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
drlNonThreaded[r] = time;
log.warn("*************** Time for {} non-threaded drl: {} ms", EXECUTIONS, time);
}
}
@Test
public void should_run_drl_threaded() throws InterruptedException
{
final ExecutorService executorService = newFixedThreadPool(THREADS);
for (int r = 0; r < RUNS; r++)
{
final CountDownLatch latch = new CountDownLatch(EXECUTIONS);
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
executorService.submit(() -> {
KieSession kieSession = kieBase.newKieSession();
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
latch.countDown();
});
}
//Wait for all threads to finish
latch.await();
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
drlThreaded[r] = time;
log.warn("*************** Time for {} threaded drl: {} ms", EXECUTIONS, time);
}
executorService.shutdown();
}
@Test
public void should_run_kbase_not_threaded()
{
final KieContainer kieContainer = KieServices.get().newKieClasspathContainer();
for (int r = 0; r < RUNS; r++)
{
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
KieSession kieSession = kieContainer.getKieBase(TEST_KBASE).newKieSession();
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
}
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
kbaseNonThreaded[r] = time;
log.warn("*************** Time for {} non-threaded kbase: {} ms", EXECUTIONS, time);
}
}
@Test
public void should_run_kbase_threaded() throws InterruptedException
{
final ExecutorService executorService = newFixedThreadPool(THREADS);
final KieContainer kieContainer = KieServices.get().newKieClasspathContainer();
for (int r = 0; r < RUNS; r++)
{
final CountDownLatch latch = new CountDownLatch(EXECUTIONS);
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
executorService.submit(() -> {
KieSession kieSession = kieContainer.getKieBase(TEST_KBASE).newKieSession();
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
latch.countDown();
});
}
//Wait for all threads to finish
latch.await();
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
kbaseThreaded[r] = time;
log.warn("*************** Time for {} threaded kbase: {} ms", EXECUTIONS, time);
}
executorService.shutdown();
}
@Test
public void should_run_kjar_not_threaded()
{
final KieContainer kieContainer = KieServices.get().newKieClasspathContainer();
for (int r = 0; r < RUNS; r++)
{
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
KieSession kieSession = kieContainer.newKieSession(TEST_KSESSION);
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
}
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
kjarNonThreaded[r] = time;
log.warn("*************** Time for {} non-threaded kjar: {} ms", EXECUTIONS, time);
}
}
@Test
public void should_run_kjar_threaded() throws InterruptedException
{
final ExecutorService executorService = newFixedThreadPool(THREADS);
final KieContainer kieContainer = KieServices.get().newKieClasspathContainer();
for (int r = 0; r < RUNS; r++)
{
final CountDownLatch latch = new CountDownLatch(EXECUTIONS);
final Stopwatch stopwatch = createStarted();
for (int i = 0; i < EXECUTIONS; i++)
{
executorService.submit(() -> {
KieSession kieSession = kieContainer.newKieSession(TEST_KSESSION);
CommandExecutor exec = kieSession;
Command fireCmd = new FireAllRulesCommand();
Command batchCmd = new BatchExecutionCommandImpl(newArrayList(fireCmd));
exec.execute(batchCmd);
kieSession.dispose();
latch.countDown();
});
}
//Wait for all threads to finish
latch.await();
//Total time
final long time = stopwatch.stop().elapsed(MILLISECONDS);
kjarThreaded[r] = time;
log.warn("*************** Time for {} threaded kjar: {} ms", EXECUTIONS, time);
}
executorService.shutdown();
}