Edson -
Thank you very much for the reply. I have one more
question. In the example below I changed RulesUtil to be a
global name 'ruleUtil' (since its member variables do not change), and reran the
rule (with the 'ruleUtil:RulesUtil()' line omitted).
When I do this, and execute the rule below, I get a null
pointer exception on PredicateConstraint. The first and last
parts of the stack trace are:
org.drools.RuntimeDroolsException: Exception executing
predicate com.bah.aims.rules.Rule_my_rule_0ReturnValue0Invoker@36289b82
at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:216)
at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:132)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:140)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:299)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
...
Caused by: java.lang.NullPointerException
at
com.bah.aims.rules.Rule_my_rule__0.returnValue0(Rule_my_rule_0.java:27)
at
com.bah.aims.rules.Rule_my_rule_0ReturnValue0Invoker.evaluate(Rule_myRule_0ReturnValue0Invoker.java:21)
at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:210)
...
29 more
I'm not sure what is causing this. Any
thoughts?
If it helps, RulesUtil.containsKeywordString() checks
to see if a string passed in is present in a list of keywords held in the
class.
Thanks -
David
David,
Eval is really bad for perf, but still, sometimes it
is the only way to do things like call methods. So, in your case, it all depends
on what "containsKeywordString()" method is doing?
Also, is RulesUtil just a utility class? I mean with no data you reason over? if
so, I strongly advise you to make it a global, instead of matching it in the
rule like a fact.
Regarding evals, inline evals are just a
bit lighter than top level evals, but there is an important difference:
*
inline evals MUST be time consistent, i.e., they must evaluate to the same value
everytime they are called.
* top level evals can deal with changes
appropriately
[]s
Edson
2008/9/15 Warren, David [USA]
<warren_david@bah.com>
Folks -
After seeing the thread
on evals hurting performance a couple of
weeks ago, I tried to remove them from a rule set we are
using (running Drools 4.0.4), and have had limited
success.
An example
is shown below. We're using evals every time we make a call to
"rulesUtil", a helper class we have for checking strings for keywords.
Two questions:
1. Does using inline evals (like below) hurt performance as
much as using non-inline evals?
2. If
so, any thoughts for how to rewrite this rule to avoid using the
eval?
rule
'my rule'
salience 790
activation-group "priorityRule"
when
ruleUtil : RulesUtil( )
s1 : Sensor( source == "X, $rfp : RFP , eval(
ruleUtil.containsKeywordString($rfp, "Y"
)) , $tcn : TCN)
s2 : Sensor( TCN != $tcn, source ==
"Z"
then
System.out.println("my rule");
priority.setPriorityName("A");
end
Thanks,
David
Warren
Start by eliminating the evals and writing your
constraints properly inside the patterns. Drools 3+ is orders of magnitude
faster than Drools 2.x, but you need to leverage its power in your rules.
Please read the manual as the version 3 was a completely rewrite of version 2.
Version 4 is an improvement over 3.
As an example, look at
this:
http://blog.athico.com/2006/11/rush-hour-and-content-based-routing.html
[]s
Edson
2008/9/5 Rout, Sushanta (ThoughtMill)
<Sushanta.Rout@ihg.com>
We
were using Drools 2.5 version earlier. Now we have switched to drools
4.0.7. But we see significant issues
with performance like drools 4.0.7
is three times slower than 2.5 . Has
anybody encountered the issue?
Here is a sample of the rule, we have
some more similar to this.
rule "test"
dialect "java"
activation-group
"group1"
when
$croNumberDetailsRequest :
CRONumberDetailsRequest()
$resdirectPhoneNumber : ResdirectPhoneNumber()
eval($resdirectPhoneNumber.getType().getId() == 5
&&
$resdirectPhoneNumber.isValidForBrand($croNumberDetailsRequest.getBrand(
))
&&
$croNumberDetailsRequest.getRegion() != null
&&
$resdirectPhoneNumber.isValidRegion($croNumberDetailsRequest.getRegion()
)
&&
$croNumberDetailsRequest.getLocale() != null
&&
$resdirectPhoneNumber.isValidForLocaleId($croNumberDetailsRequest.getLoc
ale())
&&
$resdirectPhoneNumber.isValidSlot($croNumberDetailsRequest.getSlot()));
then
ResultList.add($resdirectPhoneNumber);
end
_______________________________________________
rules-users
mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss,
a division of Red Hat @
www.jboss.com
_______________________________________________
rules-users
mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a
division of Red Hat @
www.jboss.com