Does JBoss Drools really execute all rules in parallel?

6.8k views Asked by At

I've read a lot of documentation of JBoss Drools but cannot find a definitive answer as to if all rules are executed concurrently (certainly they are fired concurrently). More specifically, for a single input and a rule set of say 1000 rules, do the "when" conditions and the "then" conditions in each rule, execute sequentially one by one, or in parallel at the same time.

On the one hand the rete algorithm implies parallelism, certainly when the select nodes are collapsed. However after the nodes are optimized is the evaluation sequential? And the beta memory and join nodes look like they should be executed concurrently, but are they?

Also, Drools documentation speaks of "sequential mode", saying this is turned off by default. So what is turned on, parallel mode? And there is a maxThreads option implying threading.

On the other hand, I was told that the code does not utilize threading and so evaluates concurrently but executes, on the most part sequentially.

Has anyone seen any documentation that prooves the case either way?

Thanks!

2

There are 2 answers

4
Mark Proctor On BEST ANSWER

There is no indication of parallelism in the standard rete algorithm. A conflict set is produced of matched rules, the agenda then applies a strategy for firing those rules in turn.

Over the years a number of efforts have been done to parallelise part(s) of the rete, either during the matching or firing stages.

A big problem when firing all rules in parallel is determinstic execution.

We are currently exploring various strategies to concurrent and parallel matching, in Drools. We will explore concurrent rule firing too, but we need to find more robust ways for users to indicate what can be fired in parallel and what can't; so that the user gets deterministic execution where they need it.

0
Shengjie Luo On

It looks like that you have solved the problem, but I can still provide some more information if you need. There is a concurrent library used in the source code of Drools, the github web link is shown, https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/concurrent/ExecutorProviderImpl.java.

Some points,

  1. Sure, the thread factory is used in the operation executor. And you can find the thread library if you read the source code shown in this weblink.

  2. Also you ask about the maxThread, the threadpool used in Drools does have a pool size as shown in the source code. newExecutor = new ThreadPoolExecutor( Pool.SIZE, Pool.SIZE, 60L, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(), threadFactory );