Drools rules writing best practice
Asked Answered
V

2

5

I have been reading an article about Drools performance ( JBoss Drools – Performance and Memory Internals ) , it explains how Rete trees and nodes are created, how Drools indexes them, and why increasing number of objects in Drools hardly effects the total time taken to execute it. Rules, written in intelligent way can drastically reduce the number of nodes in the Rete Tree, thus, further increasing the performance.

I would like to know if there is a Drools rules writing best practice, so I can write them in a way that they could be executed as fast as possible.

Thanks.

Vacillation answered 7/11, 2012 at 13:41 Comment(1)
I'd recommend reading Wolfgang Laune's "Design Patterns in Production Systems" whitepaper. It's the only thing I have seen making a decent attempt to document rule design best practice in Drools. You can download it from Red Hat in exchange for a few contact details: engage.redhat.com/forms/rule-design-patternsRobey
H
4

I can list a few...

  • Put the most restricting condition on the top
  • use the same order of conditions across your rules
  • do not use eval unless you have to.
  • put evals at the bottom of your conditions
  • do not use if statements inside consequences
  • using shortcuts for booleans cause JIT errors on Drools 5.4 so do use them as House ( windowOpen == true ) not House ( windowOpen )
  • do not use salience, in most cases it leads to maintenance hell.

It is of course not complete, just my 2 cents...

Heatherheatherly answered 8/11, 2012 at 20:49 Comment(0)
N
3

I have very recently started working on the same, so may be I not the perfect person to answer this question, but yet,

  • The conditions that you feel should be on the highest priority put them on the top
  • The then conditions that you use should be very diligently prepared.
  • Plan using a Eclipse-Drool UI to create good rules
  • Never attempt using if-statements inside the then part
  • Use Shortcuts for Boolean, because they often cause errors
  • always follow the pattern of RWTE i.e, 1. RULE 2. WHEN 3. THEN 4. END
  • Avoid using salience, it causes troubles in most cases
  • Try to integrate the rules with custom classes rather than predefined set to be used for your operations
  • The condition that you are using for when part should be interlinked and not null(i.e, the condition should be linked to some values which have existence).
  • Use the Import statements properly...
  • Absolutely The List of this is never-ending, so keep updating yourself.... :)
Nolanolan answered 13/2, 2014 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.