On 4 May 2012 19:16, Mike Goldner <span dir="ltr"><<a href="mailto:mike@thegoldners.com" target="_blank">mike@thegoldners.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="font-size:14px;font-family:Arial,sans-serif;word-wrap:break-word"><div><div><div>Wolfgang,</div><div><br></div><div>Unfortunately, it would be very difficult to introduce a procedural/algorithmic "branch" into the program flow.</div>
<div> </div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-size:14px;font-family:Arial,sans-serif;word-wrap:break-word">
<div><div><div></div><div>Would it be possible to mimic a procedural approach within the rule using an accumulate function to extract the desired array element and then process the rest of the rule's login?</div><div>
<br></div></div></div></div></blockquote><div><br>The example withholds all the details. I don't see any array elements. <br><br>The rule determines a triplet of Data facts that's "close together", and this is done for all Data objects.<br>
It would be better to have a "rover" Data pointer that does this for the "current", and moves on to the<br>next "after", computing another "after". Start the rover with a minimum position.<br>
<br>But, given you have all the Data facts, this can be computed procedurally, triggered by a rule, done<br>on the rule's RHS.<br><br>-W<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-size:14px;font-family:Arial,sans-serif;word-wrap:break-word"><div><div><div></div><div><div><font color="rgb(0, 0, 0)"><font face="Calibri">Mike Goldner</font></font></div><div>m: <a href="tel:617.909.3009" value="+16179093009" target="_blank">617.909.3009</a></div>
</div></div></div><div><br></div><span><div style="border-right:medium none;padding-right:0in;padding-left:0in;padding-top:3pt;text-align:left;font-size:11pt;border-bottom:medium none;font-family:Calibri;border-top:#b5c4df 1pt solid;padding-bottom:0in;border-left:medium none">
<span style="font-weight:bold">From: </span> Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>><br><span style="font-weight:bold">Reply-To: </span> Rules Users List <<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br>
<span style="font-weight:bold">Date: </span> Friday, May 4, 2012 1:05 PM<br><span style="font-weight:bold">To: </span> Rules Users List <<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br>
<span style="font-weight:bold">Subject: </span> Re: [rules-users] Performance issues with a rule that includes LHS functions<br></div><div><br></div>Looks like an anti-pattern to me: you can expect O(n^3) effort for inserting Data facts.<br>
<br>This is something where a procedural/algorithmic solution is preferable to a <br>rule based solution. <br><br>-W<br> <br><br><div class="gmail_quote">
On 4 May 2012 18:44, Mike Goldner <span dir="ltr"><<a href="mailto:mike@thegoldners.com" target="_blank">mike@thegoldners.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a rule that is suffering severe performance degradation as I insert<br>
facts into the (stateful) session. In my simplified example, the first<br>
100 fact insertions take less than 10ms per fact. By the 1000th fact,<br>
insertions are taking about 850ms per fact. In production, the impact is<br>
much more severe, reaching 5000ms or more by the 1000th insertion. The<br>
number of facts per execution can vary from a few hundred to a few<br>
thousand.<br><br>
I've created a simplified example that demonstrates the problem: Imagine<br>
that there is a line plotted through a 3-dimensional plane and it is<br>
necessary to ensure that each plotted coordinate is an equal distance from<br>
the adjacent coordinates. I realize that the math isn't correct, but it<br>
is sufficient for the example.<br><br>
The constraint (and source of performance degradation) imposed by my data<br>
source is that the plane (X, Y, or Z) is variable and it is defined by an<br>
separate index that serves as a pointer into the coordinate list. If I<br>
remove the function calls, the problem disappears.<br><br>
Any suggestions on how I could rewrite the rule?<br><br>
Here is my rule:<br><br>
package test;<br><br>
declare Data<br>
plane : int<br>
coordinates : java.util.List<br>
end<br><br>
rule "Performance degradation with functions."<br>
dialect "mvel"<br>
when<br>
$current : Data( $currentPosition : getPosByAxis(plane, coordinates) )<br>
$before : Data( $beforePosition : getPosByAxis(plane, coordinates) <<br>
$currentPosition)<br>
not Data( getPosByAxis(plane, coordinates) > $beforePosition && <<br>
$currentPosition)<br>
$after : Data($afterPosition : getPosByAxis(plane, coordinates) ><br>
$currentPosition)<br>
not Data(getPosByAxis(plane, coordinates) < $afterPosition && ><br>
$currentPosition)<br>
eval ( ($currentPosition - $beforePosition) == ($afterPosition -<br>
$currentPosition) )<br>
then<br>
System.out.println("Rule RHS fired.");<br>
end<br><br>
function Double getPosByAxis(int plane, java.util.List coordinates) {<br><br>
return (Double) coordinates.get(plane);<br><br>}<br><br>
Thanks,<br><br>
Mike Goldner<br><br><br>
_______________________________________________<br>
rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</blockquote></div><br>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</span></div>
<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>