[rules-users] Performance of collect seems to be n-squared

Edson Tirelli ed.tirelli at gmail.com
Mon Feb 13 15:12:12 EST 2012


   Just FYI, the array list is created once and reused with incremental
addition/removal of elements.

   The problem is that the engine does not know when you are done inserting
all the Post facts, so each post inserted is propagated down the network
with the cancellation and reactivation of the rule.

   This is one of those situations where a use of a control fact might be
recommended, if you are inserting Post facts in batches. E.g.:

rule X
when
     exists( AllPostsInserted() )
     $a : ArrayList(size > 0) from collect(Post());
then
...
end

   Edson


2012/2/13 Wolfgang Laun <wolfgang.laun at gmail.com>

> Repeatedly creating this ArrayList is bound to be O(n2).
>
> Why do you want the Post facts as a List? There may be better ways for
> achieving your goal.
>
> -W
>
>
>
> On 13 February 2012 20:49, Shur, Bob <robert.shur at hp.com> wrote:
>
>> I have a simple class Post { int id; ... }. I insert some number of them
>> as facts and then call ksession.execute(facts);
>>
>> The whole drl file (except for package and import statements) is:
>>
>> rule "collect"
>> when
>>        $a : ArrayList(size > 0) from collect(Post());
>> then
>>        System.out.println("Number of posts: " + $a.size());
>>        System.out.println("DONE");
>> end
>>
>> The time it takes to run is n-squared in the number of posts. For 4000,
>> 8000, 16000, 32000, 64000 posts the time is (in 1/10 seconds):
>>
>> 4, 14, 56, 220, 852
>>
>> Is this expected? Is there a better way for me to do the collect?
>>
>>
>> _______________________________________________
>> 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
>
>


-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120213/fdaf8910/attachment.html 


More information about the rules-users mailing list