Hello,
I'm new to Drools and am trying it out. I've found it easy enough so
far, but quickly ran into a performance bottleneck. (perhaps an all
too familiar story! :) ). So, I made a simple example to try and
track down the behavior. Here it is.
I wanted to create a rule that uses an < comparison between pairs of
objects. The following are the performance results:
10 objects. Java comparison took 0 ms
10 objects. Rule firing took 2516 ms
100 objects. Java comparison took 0 ms
100 objects. Rule firing took 1984 ms
1000 objects. Java comparison took 47 ms
1000 objects. Rule firing took 132500 ms
10000 objects. Java comparison took 4641 ms
10000 objects. Rule firing took .... (please wait...)
Here is the rule
rule "A < B"
when
a : TestObject( )
b : TestObject( valueDouble < a.valueDouble )
then
b.setValueint(b.getValueint()+1);
end
Now, I do understand that this (worst-case) is a comparison of N x N
objects... so, 1000 = 1000000 comparisons. However, ~100ms per
comparison seems relatively expensive for such a simple check. I am
using StatefulKnowledgeSession (I tried Stateless but this gave only a
mild performance improvement - and I would also like to use insert in
some of my rules).
How would one speed up such a query? I know part of the problem is
the < comparison. The results with == are much better (presumably, it
can do lots of pruning of the space)
Model creation 0
10 objects. Rule firing took 2829 ms
100 objects. Rule firing took 93 ms
1000 objects. Rule firing took 657 ms
10000 objects. Rule firing took 3375 ms
100000 objects. Rule firing took 33266 ms
I have thought about clever tricks that I could do to try and speed
things up, like sorting into groups, etc. But it all seems relatively
convoluted. Am I correct in coming to the conclusion that a <
comparison is not the kind of thing that you should do in Drools?
How would you go about this? I would prefer to keep all the logic in
the DRL files. I'm guessing you do a Java based comparison and use a
fire-once rule to invoke this code.
Thanks in advance for any insight,
Tom