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.

4

1 回答 1

0

您的规则没有定义自动撤回的时间限制,before并且after不受限制。

有几种方法可以将事件数量保持在较低水平,这就是插入速度越来越慢的原因。这是一个简单的技术:

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
于 2014-07-15T06:18:35.430 回答