Any question is also
about performance consideration. See below example:
Rule “1”
Dialect
“mvel”
Salience
300
No-loop
true
When
$acctsrc:
data(sourceid==1)
$reposrc:
data((sourceid==2||sourceid==5)&&amount==acctsrc.amount)
Then
…
End
Two questions here:
1.
In this
kind of join conditions, is there any best practice to follow in the rule? I
heard from somebody that I need to put data who have less # of transactions
first in my when expression. For example, if I have less number of $reposrc
transactions in facts, I should put it ahead of $acctsrc to gain better
performance. Is this valid?
2.
Do we
know how to create an event listener in the rule for logging purpose rather
than standard log4j? It was recommended in some other articles as well. Is this
also valid? (http://www.technologyblue.com/docs/presentations/DroolsBestPractices.pdf);
Ultimately, is there
any place I can find a best practice of rule development as a generic guide?
Best
Abe
发件人: Zhuo Li
[mailto:milanello1998@gmail.com]
发送时间: 2011年12月26日 16:51
收件人: 'Rules Users List'
主题: Performance
consideration in rule writing
Hi, team,
I have some quick questions here regarding
performance best practices of rule writing. See below two pieces of rules:
Rule “1”
Salience 100
No-loop true
When $txn : data(sourceid == 5&&txnjustify==”995”&&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEquals($txn)==0&&compareToPostThreshold($txn)==2);
Then
…
End
Rule “2”
Salience 100
No-loop true
When $txn : data(sourceid ==
5&&txnjustify==”995”&&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEquals($txn)==0&&compareToPostThreshold($txn)==1);
Then
…
End
Questions:
1.
Will I gain better performance
if I put the rule differentiator condition “compareToPostThreshold($txn)==2” at
the beginning of both rule 1 and 2?
2.
I saw salaboy’s video claiming
that to avoid using eval() in the rule. Do we have any alternative way to do
that from a performance consideration or I’d better collect/ prepare all the
data before I send them into the session?
3.
What’s you guys’ naming
convention for rule’s salience?
PS: my Drools version is 5.2.0.
Best regards
Abe