I've been trying to optimize our stateful rules to run a bit faster,
currently they can't quite keep up with the events coming into the session.
A lot of our rules have to find the fact whose attribute is the
smallest/largest value of all the facts of that type in working memory. I
had originally written the rules to do a min accumulate to find the min
value of the attribute, then a regular pattern to find the actual fact with
that min value. Some of the fact types actually have two fields that must
be used to find the min - think of them as a category and a score. For
those I did two accumulate mins, one to find the lowest category, one to
find the lowest score in that category, and then a third rule to find the
fact with that min category and min score.
I recently refactored all the rules to use the paradigm of one rule that
matches the fact type I'm interested in, and a second rule that uses the not
operator to express that there be no facts whose attribute is a higher value
than the fact I just matched. In the contrived test I wrote, this seemed to
perform better, but it's hard to tell if they are performing better or not
with production data flowing through them.
I know of a third option - writing my own accumulate functions - which I
will probably try next. This should allow me to find the min/max fact with
just one iteration over the facts, vs multiple iterations like my first
approach. I don't know how it will compare to using the exists method
though.
Any feedback on these three different approaches? Any other ideas on the
best way to do this?
--
View this message in context:
http://drools.46999.n3.nabble.com/Best-performing-way-to-process-facts-in...
Sent from the Drools: User forum mailing list archive at
Nabble.com.