0

I have a rule that looks for 2 consecutive events for the same entity. To stress test it, I inserted 10K consecutive events. I'm calling fireAllRules() after each event is inserted. I'm printing out timestamps after every 100 events. I'm noticing that insertions/evaluations are increasingly slower as events are added. Here's the rule :

rule "Consecutive events"
when
    $latest : Event($id : id) // newest event
    not Event(id == $id, this after $latest) // no events after the newest
    $previous : Event(id == $id, this before $latest) // event before the newest
    not Event(id == $id, this before $latest, this after $previous) // no events between $latest and $previous
then
    //System.out.println($latest.toString());
end

It is my understanding that the above rule should only match the latest 2 events and automatic memory management should remove older events. If so, why are insertions progressively slower? Interestingly, ksession.getObjects() returns all the events inserted and not just the latest 2 events. Is my understanding of the rule incorrect? Does the rule somehow force all events to stay in memory? I'm using v6.0.1.Final.

Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
sumantp
  • 3
  • 2

1 Answers1

0

Your rule does not define a time limit for automatic retraction as the before and after are not limited.

There are several ways to keep the number of events low, which is the reason for inserts getting progressively slower. Here is a simple technique:

declare Pair
 one : Event
 two : Event
 id : String
end

rule "create Pair"
when
  $e: Event( $id: id )
  not Pair( id == id ) 
then
  insert( new Pair( null, $e, $id ) );
end

rule "another Pair"
when
  $e2: Event( $id: id )
  $p: Pair( $e0: one, $e1: two != $e2, id == $id )
then
  modify( $p ){
    setOne( $e1 ),
    setTwo( $e2 ) }
  retract( $e0 ); // optional
  // process pair $e1, $e2 
end
laune
  • 31,114
  • 3
  • 29
  • 42
  • Thanks! your technique worked like a charm after some small modifications - mainly, using no-loop in the "another Pair" rule. – sumantp Jul 15 '14 at 17:41