2011/12/26 Zhuo Li <span dir="ltr"><<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
So for #1, you mean it is more from static variable safety to put uncommon<br>
conditions at the beginning of LHS?<br></blockquote><div><br>A static variable or a DRL global is something that must be used with caution in a rule's LHS. In any case, if it is read, it should be used like a constant; if you modify it, it should be used like a one-way outoing service.<br>
<br> </div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
On #3, can you elaborate more about " Making your rules depend on salience<br>
isn't good practice "? in general, what we need to define in every rule file<br>
is a business case, and every case stands for a flow with things like<br>
if-elseif-else. I guess you mean I may use Drools flow or Java itself to<br>
control the flow and leave judgment inside Drools?</blockquote><div><br>Think of "flow" (either by Drools or by Java) as a high-level progress through application stages or phases. Salience is better restricted to precedence within flow groups, and there I don't recommend more than three levels. <br>
</div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex"> If that's the case, the<br>
original concern we had was it will have too many insert() into<br>
workingmemory which may impact performance...<br></blockquote><div><br>I don't see how one would require the other. Inserts are indicated if you derive new facts that need to be evaluated in subsequent rules.<br> <br>
-W<br></div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204,204,204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
<br>
Best<br>
Abe<br>
<br>
-----邮件原件-----<br>
发件人: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] 代表 Wolfgang Laun<br>
发送时间: 2011年12月26日 23:15<br>
收件人: Rules Users List<br>
主题: Re: [rules-users] 答复: Performance consideration in rule writing<br>
<br>
On 26/12/2011, Zhuo Li <<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>> wrote:<br>
> //Abe: it definitely makes a difference if you put differentiator<br>
> conditions at the beginning – this way RETE won’t waste efforts<br>
> constructing networks which will not fulfill. See below example.<br>
><br>
> rule "Evaluation of assignment in r-value position"<br>
> no-loop true<br>
> when<br>
> $statement:CStatement($value:value)<br>
> eval(Matcher.isRVExpression($value))<br>
><br>
> eval(0==Matcher.getClauseNum())<br>
> then<br>
> System.out.println($value);<br>
> modify($statement){<br>
> setSemantics(Matcher.getRVSemantics(memory,$value));<br>
> }<br>
> end<br>
><br>
> rule "Evaluation of assignment clause in r-value position without<br>
> updating memory"<br>
> no-loop true<br>
> when<br>
> $statement:CStatement($value:value)<br>
> eval(Matcher.isRVExpression($value))<br>
><br>
> eval(0<Matcher.getClauseNum())<br>
> then<br>
> System.out.println("=="+$value);<br>
> Matcher.decreaseClauseNum();<br>
> modify($statement){<br>
> setSemantics(Matcher.getRVSemanticsWithoutUpdate(memory,$value));<br>
> }<br>
> end<br>
><br>
<br>
This is quite different from the rules in the original post. It is generally<br>
not advisable to access and modify static variables, here:<br>
clauseNum in class Matcher, i.e., not a fact.<br>
<br>
<br>
><br>
<br>
> //Abe: I saw below statement from Drools document 5.2.0. As Eval is<br>
> not indexed, overuse of evale reduces the rules’ clarity and will<br>
> result in a bad performance.<br>
<br>
Needlessly using eval is not good; if you have to use it you won't be able<br>
to avoid it.<br>
<br>
<br>
><br>
><br>
> 3. What’s you guys’ naming convention for rule’s salience?<br>
><br>
> Not clear what you mean by that.<br>
><br>
> //Abe: I mean how do you weight your salience values across different<br>
rules.<br>
> I’ve seen various styles in my project – somebody uses 100, 200, 300<br>
> but somebody uses 90, 100, 110, 120, etc. This is not a big problem as<br>
> they are working on different rules and won’t pollute each other.<br>
> However I would still try to make it consistent so maintain each<br>
> other’s rule files will be easier…<br>
<br>
Making your rules depend on salience isn't good practice, certainly not with<br>
more than 3 levels (my personal definition). The sort of multi-level<br>
salience you're indicating could be an indication that procedural style<br>
if-then-elsif logic has been fitted into rules.<br>
<br>
-W<br>
><br>
><br>
><br>
> 发件人: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] 代表 Wolfgang Laun<br>
> 发送时间: 2011年12月26日 22:20<br>
> 收件人: Rules Users List<br>
> 主题: Re: [rules-users] Performance consideration in rule writing<br>
><br>
><br>
><br>
> See below.<br>
><br>
> 2011/12/26 Zhuo Li <<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>><br>
><br>
> Hi, team,<br>
><br>
><br>
><br>
> I have some quick questions here regarding performance best practices<br>
> of rule writing. See below two pieces of rules:<br>
><br>
><br>
><br>
> Rule “1”<br>
><br>
> Salience 100<br>
><br>
> No-loop true<br>
><br>
> When $txn : data(sourceid == 5&&txnjustify==”995”<br>
> &&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEqual<br>
> s($txn )==0&&compareToPostThreshold($txn)==2);<br>
><br>
> Then<br>
><br>
> …<br>
><br>
> End<br>
><br>
><br>
><br>
> Rule “2”<br>
><br>
> Salience 100<br>
><br>
> No-loop true<br>
><br>
> When $txn : data(sourceid == 5&&txnjustify==”995”<br>
> &&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEqual<br>
> s($txn )==0&&compareToPostThreshold($txn)==1);<br>
><br>
> Then<br>
><br>
> …<br>
><br>
> End<br>
><br>
><br>
><br>
> Questions:<br>
><br>
> 1. Will I gain better performance if I put the rule differentiator<br>
> condition “compareToPostThreshold($txn)==2” at the beginning of both<br>
> rule<br>
> 1 and 2?<br>
><br>
> One kind pf Rete optimization is based on evaluating common<br>
> constraints once, therefore: no.<br>
><br>
><br>
> 2. I saw salaboy’s video claiming that to avoid using eval() in the<br>
> rule. Do we have any alternative way to do that from a performance<br>
> consideration<br>
><br>
> Constraints based on fields using == are best. Other things may result<br>
> in eval-like evaluations anyway. Most of the time, it isn't eval that<br>
> causes performance setbacks.<br>
><br>
> or I’d better collect/ prepare all the data before I send them into<br>
> the session?<br>
><br>
> Not clear what you mean by this, but if you can provide attributes<br>
> that lend themselves to straightforward constraints it might be<br>
> worthwhile considering some up-front processing of facts.<br>
><br>
><br>
> 3. What’s you guys’ naming convention for rule’s salience?<br>
><br>
> Not clear what you mean by that.<br>
><br>
> -W<br>
><br>
><br>
><br>
><br>
> PS: my Drools version is 5.2.0.<br>
><br>
><br>
><br>
> Best regards<br>
><br>
> Abe<br>
><br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
><br>
><br>
<br>
<br>
<br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>