5

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!

user1393285
  • 73
  • 1
  • 4

2 Answers2

10

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.

Mark Proctor
  • 691
  • 4
  • 5
  • Thank you very much, I appreciate your responding. I've been following your BRMS work at rule speak and the redhat summits and have evaluated drools for adoption. I found the drool libraries and technologies very easy to understand and simple to integrate into a bespoke BRMS system. Best of luck parallelizing, I suppose an independent agenda group per thead is too crude a solution :) – user1393285 May 16 '12 at 13:20
  • Could you please elaborate on the consequences of non-deterministic execution. I would imagine that you would still get the right result, perhaps the downside would be executing rules that are not needed. – Arturo Hernandez Oct 17 '13 at 21:07
  • "I suppose an independent agenda group per thead is too crude a solution :)" If you remove all sharing between groups, and also ensure that there are no overlaps in mutations between groups, this would be possible. The moment one group can change a fact, that another group could potentially read, you have table or engine level locks. The only way around that is to use optimistic style MVCC locking. – Mark Proctor Oct 28 '13 at 18:57
  • "Could you please elaborate on the consequences of non-deterministic execution. I would imagine that you would still get the right result, perhaps the downside would be executing rules that are not needed" It depends on the rules, the order rules fire can definitely give you different results. What if a rule fires first, removing data, so other rules don't fire. If those other rules where to fire firs, they might add or update paper. There are papers out there that suggest additional syntax so that authors can provide hints to the engine on how to do it safely. – Mark Proctor Oct 28 '13 at 19:04
1

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 );