2011/12/26 Zhuo Li <span dir="ltr">&lt;<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>&gt;</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&#39;s LHS. In any case, if it is read, it&nbsp; should be used like a constant; if you modify it, it should be used like a one-way outoing service.<br>
<br>&nbsp;</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 &quot; Making your rules depend on salience<br>
isn&#39;t good practice &quot;? 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 &quot;flow&quot; (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&#39;t recommend more than three levels. <br>
&nbsp;</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&#39;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&#39;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>&nbsp;<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 &lt;<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>&gt; wrote:<br>
&gt; //Abe: it definitely makes a difference if you put differentiator<br>
&gt; conditions at the beginning &ndash; this way RETE won&rsquo;t waste efforts<br>
&gt; constructing networks which will not fulfill. See below example.<br>
&gt;<br>
&gt; rule &quot;Evaluation of assignment in r-value position&quot;<br>
&gt; no-loop true<br>
&gt; when<br>
&gt; &nbsp;$statement:CStatement($value:value)<br>
&gt; &nbsp;eval(Matcher.isRVExpression($value))<br>
&gt;<br>
&gt; &nbsp;eval(0==Matcher.getClauseNum())<br>
&gt; then<br>
&gt; &nbsp;System.out.println($value);<br>
&gt; &nbsp;modify($statement){<br>
&gt; &nbsp; setSemantics(Matcher.getRVSemantics(memory,$value));<br>
&gt; &nbsp;}<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;Evaluation of assignment clause in r-value position without<br>
&gt; updating memory&quot;<br>
&gt; no-loop true<br>
&gt; when<br>
&gt; &nbsp;$statement:CStatement($value:value)<br>
&gt; &nbsp;eval(Matcher.isRVExpression($value))<br>
&gt;<br>
&gt; &nbsp;eval(0&lt;Matcher.getClauseNum())<br>
&gt; then<br>
&gt; &nbsp;System.out.println(&quot;==&quot;+$value);<br>
&gt; &nbsp;Matcher.decreaseClauseNum();<br>
&gt; &nbsp;modify($statement){<br>
&gt; &nbsp; setSemantics(Matcher.getRVSemanticsWithoutUpdate(memory,$value));<br>
&gt; &nbsp;}<br>
&gt; end<br>
&gt;<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>
&gt;<br>
<br>
&gt; &nbsp;//Abe: I saw below statement from Drools document 5.2.0. As Eval is<br>
&gt; not indexed, overuse of evale reduces the rules&rsquo; clarity and will<br>
&gt; result in a bad performance.<br>
<br>
Needlessly using eval is not good; if you have to use it you won&#39;t be able<br>
to avoid it.<br>
<br>
<br>
&gt;<br>
&gt;<br>
&gt; 3. &nbsp; &nbsp; &nbsp; What&rsquo;s you guys&rsquo; naming convention for rule&rsquo;s salience?<br>
&gt;<br>
&gt; Not clear what you mean by that.<br>
&gt;<br>
&gt; //Abe: I mean how do you weight your salience values across different<br>
rules.<br>
&gt; I&rsquo;ve seen various styles in my project &ndash; somebody uses 100, 200, 300<br>
&gt; but somebody uses 90, 100, 110, 120, etc. This is not a big problem as<br>
&gt; they are working on different rules and won&rsquo;t pollute each other.<br>
&gt; However I would still try to make it consistent so maintain each<br>
&gt; other&rsquo;s rule files will be easier&hellip;<br>
<br>
Making your rules depend on salience isn&#39;t good practice, certainly not with<br>
more than 3 levels (my personal definition). The sort of multi-level<br>
salience you&#39;re indicating could be an indication that procedural style<br>
if-then-elsif logic has been fitted into rules.<br>
<br>
-W<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 发件人: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
&gt; [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] 代表 Wolfgang Laun<br>
&gt; 发送时间: 2011年12月26日 22:20<br>
&gt; 收件人: Rules Users List<br>
&gt; 主题: Re: [rules-users] Performance consideration in rule writing<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; See below.<br>
&gt;<br>
&gt; 2011/12/26 Zhuo Li &lt;<a href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>&gt;<br>
&gt;<br>
&gt; Hi, team,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I have some quick questions here regarding performance best practices<br>
&gt; of rule writing. See below two pieces of rules:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Rule &ldquo;1&rdquo;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Salience 100<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;No-loop true<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;When $txn : data(sourceid == 5&amp;&amp;txnjustify==&rdquo;995&rdquo;<br>
&gt; &amp;&amp;eval(creditOption($txn)==1)&amp;&amp;eval(isGCSwitch($txn))&amp;&amp;isCurrencyEqual<br>
&gt; s($txn )==0&amp;&amp;compareToPostThreshold($txn)==2);<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Then<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&hellip;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Rule &ldquo;2&rdquo;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Salience 100<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;No-loop true<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;When $txn : data(sourceid == 5&amp;&amp;txnjustify==&rdquo;995&rdquo;<br>
&gt; &amp;&amp;eval(creditOption($txn)==1)&amp;&amp;eval(isGCSwitch($txn))&amp;&amp;isCurrencyEqual<br>
&gt; s($txn )==0&amp;&amp;compareToPostThreshold($txn)==1);<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Then<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &hellip;<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Questions:<br>
&gt;<br>
&gt; 1. &nbsp; &nbsp; &nbsp; Will I gain better performance if I put the rule differentiator<br>
&gt; condition &ldquo;compareToPostThreshold($txn)==2&rdquo; at the beginning of both<br>
&gt; rule<br>
&gt; 1 and 2?<br>
&gt;<br>
&gt; One kind pf Rete optimization is based on evaluating common<br>
&gt; constraints once, therefore: no.<br>
&gt;<br>
&gt;<br>
&gt; 2. &nbsp; &nbsp; &nbsp; I saw salaboy&rsquo;s video claiming that to avoid using eval() in the<br>
&gt; rule. Do we have any alternative way to do that from a performance<br>
&gt; consideration<br>
&gt;<br>
&gt; Constraints based on fields using == are best. Other things may result<br>
&gt; in eval-like evaluations anyway. Most of the time, it isn&#39;t eval that<br>
&gt; causes performance setbacks.<br>
&gt;<br>
&gt; or I&rsquo;d better collect/ prepare all the data before I send them into<br>
&gt; the session?<br>
&gt;<br>
&gt; Not clear what you mean by this, but if you can provide attributes<br>
&gt; that lend themselves to straightforward constraints it might be<br>
&gt; worthwhile considering some up-front processing of facts.<br>
&gt;<br>
&gt;<br>
&gt; 3. &nbsp; &nbsp; &nbsp; What&rsquo;s you guys&rsquo; naming convention for rule&rsquo;s salience?<br>
&gt;<br>
&gt; Not clear what you mean by that.<br>
&gt;<br>
&gt; -W<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; PS: my Drools version is 5.2.0.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Best regards<br>
&gt;<br>
&gt; Abe<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<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>