I'm using a single threaded drools project as a first-match policy/condition evaluation engine. I'm using the following code to get a kieSession from the kieContainer, and evaluate the predicate based on the conditions.
KieContainer currentContainer = kieContainer.get();
StatelessKieSession newKIESession = currentContainer.newStatelessKieSession();
newKieSession.execute(predicate);
The evaluation takes about 10 ms for a given request. However, to increase the performance when I used 10 threads, each of these requests starting taking about 100ms effectively giving me the same performance with a larger number of threads.
- What is the RIGHT WAY to use multi-threading to improve condition evaluation in Drools?
Should I spawn a new container for each processing thread instead spawning of a new session from existing containers?
//SEE LAST LINE BELOW KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieFileSystem kfs = ks.newKieFileSystem(); byte[] drlAsBytes = retrieveDRLResource(); kfs.write(ResourceFactory.newByteArrayResource(drlAsBytes).setTargetPath(DROOLS_DEFAULT_PATH)); KieBuilder kb = ks.newKieBuilder(kfs); kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built. if (kb.getResults().hasMessages(Level.ERROR)) { throw new PolicyServiceException("Build Errors:\n" + kb.getResults().toString()); } //******* SHOULD THIS BE DONE FOR EACH PROCESSING THREAD? ****** KieContainer newkieContainer = ks.newKieContainer(kr.getDefaultReleaseId());
I'm using the following version of DROOLS.
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>7.2.0.Final</version>
</dependency>