Reputation: 1970
I have a problem that I can solve with a rules engine, and our team already wrote apps using Drools (but I am new to it so apols for the newbie question).
One concern of mine is that one of the facts is really expensive to compute (REST calls to remote server). I guess this means the Drools 'eval' function for lazy evaluation.
But also, I really want to force this particular fact to the back of evaluation order. I really don't want the Drools algorithms to decide 'the answer of this function is a really efficient way to partition the ruleset' - maybe it is, if cost were immaterial, but this one is so much more expensive than others.
Does Drools have some tools/hacks for solving this or is it the wrong tool for this problem?
Upvotes: 0
Views: 697
Reputation: 153
eval() does not perform lazy evaluation; it simply evaluates a boolean expression that cannot be expressed in DRL's pattern syntax. It's need should be less common with 5.2 as it supports richer free-form expressions in patterns.
Regarding your specific question about expensive facts; pre-loading before using in the KnowledgeBase would probably be your best option (as Geoffey says). I assume if their computation is expensive once loaded they are pretty static.
Rumour has it, after 5.2, there are plans for asynchronous "from" so patterns can react to facts loaded asynchronously. It was mentioned in a long flight from Argentina and is best considered etherware at the moment, but push for it on the drools-user mailing list and something more concrete may come to light.
Upvotes: 1
Reputation: 27312
If you can preload the REST facts, do so, so Drools can optimize indexing (hashing) and joins on them.
If not, you have a situation similar to using hibernate directly for drools with from
.
Some things you can do:
Take a look at salience
in the manual to execute those rules last.
Also, put your eval()
last in your rule LHS.
Upvotes: 0