[rules-users] Performance issues with a rule that includes LHS functions
Wolfgang Laun
wolfgang.laun at gmail.com
Fri May 4 13:37:32 EDT 2012
On 4 May 2012 19:16, Mike Goldner <mike at thegoldners.com> wrote:
> Wolfgang,
>
> Unfortunately, it would be very difficult to introduce a
> procedural/algorithmic "branch" into the program flow.
>
>
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?
>
>
The example withholds all the details. I don't see any array elements.
The rule determines a triplet of Data facts that's "close together", and
this is done for all Data objects.
It would be better to have a "rover" Data pointer that does this for the
"current", and moves on to the
next "after", computing another "after". Start the rover with a minimum
position.
But, given you have all the Data facts, this can be computed procedurally,
triggered by a rule, done
on the rule's RHS.
-W
> Mike Goldner
> m: 617.909.3009
>
> From: Wolfgang Laun <wolfgang.laun at gmail.com>
> Reply-To: Rules Users List <rules-users at lists.jboss.org>
> Date: Friday, May 4, 2012 1:05 PM
> To: Rules Users List <rules-users at lists.jboss.org>
> Subject: Re: [rules-users] Performance issues with a rule that includes
> LHS functions
>
> Looks like an anti-pattern to me: you can expect O(n^3) effort for
> inserting Data facts.
>
> This is something where a procedural/algorithmic solution is preferable to
> a
> rule based solution.
>
> -W
>
>
> On 4 May 2012 18:44, Mike Goldner <mike at thegoldners.com> wrote:
>
>> 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
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
> _______________________________________________ rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120504/34fddf07/attachment.html
More information about the rules-users
mailing list