[rules-users] Performance issues with a rule that includes LHS functions
Mike Goldner
mike at thegoldners.com
Fri May 4 12:44:57 EDT 2012
I have a rule that is suffering severe performance degradation as I insert
facts into the (stateful) session. In my simplified example, the first
100 fact insertions take less than 10ms per fact. By the 1000th fact,
insertions are taking about 850ms per fact. In production, the impact is
much more severe, reaching 5000ms or more by the 1000th insertion. The
number of facts per execution can vary from a few hundred to a few
thousand.
I've created a simplified example that demonstrates the problem: Imagine
that there is a line plotted through a 3-dimensional plane and it is
necessary to ensure that each plotted coordinate is an equal distance from
the adjacent coordinates. I realize that the math isn't correct, but it
is sufficient for the example.
The constraint (and source of performance degradation) imposed by my data
source is that the plane (X, Y, or Z) is variable and it is defined by an
separate index that serves as a pointer into the coordinate list. If I
remove the function calls, the problem disappears.
Any suggestions on how I could rewrite the rule?
Here is my rule:
package test;
declare Data
plane : int
coordinates : java.util.List
end
rule "Performance degradation with functions."
dialect "mvel"
when
$current : Data( $currentPosition : getPosByAxis(plane, coordinates) )
$before : Data( $beforePosition : getPosByAxis(plane, coordinates) <
$currentPosition)
not Data( getPosByAxis(plane, coordinates) > $beforePosition && <
$currentPosition)
$after : Data($afterPosition : getPosByAxis(plane, coordinates) >
$currentPosition)
not Data(getPosByAxis(plane, coordinates) < $afterPosition && >
$currentPosition)
eval ( ($currentPosition - $beforePosition) == ($afterPosition -
$currentPosition) )
then
System.out.println("Rule RHS fired.");
end
function Double getPosByAxis(int plane, java.util.List coordinates) {
return (Double) coordinates.get(plane);
}
Thanks,
Mike Goldner
More information about the rules-users
mailing list