I have been using JBoss Drools 5 in my project for a while. In the beginning we were not confident about how it will fit in the project. There were also doubts about the performance and maintainability of Drools Stuff.
So, to start with, we decided to implemented a small functionality using Drools. A big list of objects was passed to drools and some functionality was implemented with Drools. This resulted in setting up the infrastructure for Drools framework along with measuring Drools performance with a big set of data.
The best thing noticed was the readability of the logic. Had the same code been written in java, no matter how readable it would have been , the java code could never surpass the crispness and simplicity of the Drools code.
Reason being, Drools has certain features which saves some amount of java code to be written . Suppose you use 5 such features and then guess the amount of java code you just saved. This in turn increased the readability of the code.
The readability of the Drools code helped in transforming the business logic whenever needed. This tempted to add more business logic in Drools.
Finally we got two layers of of Drools where we insert a large amount of objects in the Drools session, and perform a set of business rules there. The order of business rules can be controlled in Drools which give a solid control over rules. There had been times where we have just reversed the rule order. Doing this in java would not had been so easy. In Drools it was just changing some numbers.
And I must confess that I am really impressed with the efficiency with which Drools uses memory. I think Drools don’t replicate objects, rather it just creates handles to objects in java heap which results if efficient memory usage.
The performance was further improved by using some clever business logic. The rules which filtered out useful object were executed first which removed the useless objects after filtering. This significantly reduces the number of objects which results in lessening the number of executions of the rules to be fired, thus improving the efficiency.
Try to use the no loop functionality of drools, if the business logic allows that, this prevents in re executing same rule on same objects. A rule without no loop can easily cause OutOfMemory or can slow down system performance easily in some conditions.
Another performance improvement can be done by using the insert functionality of Drools which inserts new Objects in Drools session from rules. So, if few objects can be combined into one then insert the new object and retract (remove) the other objects from Drools session.
To increase the readability of the Drools code, try to combine 4-5 lines of Drools code in a single method in java and call that method from Drools rule. Drools gives the functionality to call java methods from Drools rules which helps a lot.
At the end of it, we have lots of business logic segregated in two layers which are changed very frequently, and every time we change it , we thank Drools. This has resulted in increasing the productivity of the team as well as decreasing the pain which would have been caused by altering lots of java code frequently to suit to business logic.





4 Comments
yes..I too adhere Drools.. but I don’t like the syntax.. it is a bit clumsy
Jasmine,
What is it about the syntax you don’t like, do you have any suggestions to improve this?
We are working on the new syntax for drools 6, which will be much improved. Could you provide feedback on this:
http://community.jboss.org/wiki/DroolsLanguageEnhancements
Mark
Hi,
Very interesting article. i am trying to use drools in one of the projects we have, i am facing few problems:
1. My data set is huge, we will be dealing in terms of millions of records and would “transform” them into different objects based on rules. Do you think drools is suited here?
2. How did you manage rules? in drl files? or u used drools guvnor? doesnt changing rules in drl files need a redeployment od code?
Thanks in advance,
ravi
Drools is a perfect fit for huge data set. But try to optimize it as much as u can ( By writing efficient rules).
I kept rules in .drl files. Redeployment was not a problem for me. Why dont you keep rules as an OSGi bundle, then you can just change the bundle with new rules without redeploying the code.
One Trackback
[...] JBoss Drools 5 – Effective Usage May 2010 4 comments 5 [...]