Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drools rules writing best practice

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.

like image 840
Luciano Avatar asked Nov 07 '12 13:11

Luciano


People also ask

How can you improve Drools performance of rule execution?

Preparing data before calling insert() would give you better performance. Converting drl/xls is done by KnowledgeBuilder for the first time. KnowledgeBase will be cached in an application so it wouldn't be a bottle-neck. Drools 5 evaluates rule condition during the insert stage (ksession.

How do you fire specific rules in Drools?

To associcate a Customer with rules you need: class Customer { private String name; private List<String> rules; //... } So you are saying to create agenda for each customer and fire the rules based on agenda...

What is DRL file in Drools?

DRL (Drools Rule Language) rules are business rules that you define directly in . drl text files. These DRL files are the source in which all other rule assets in Business Central are ultimately rendered.


2 Answers

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...

like image 89
ali köksal Avatar answered Sep 28 '22 21:09

ali köksal


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.... :)
like image 23
D3X Avatar answered Sep 28 '22 22:09

D3X