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">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>