<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    I 've also seen that accumulate and statefull don't always mix as
    good as they could.<br>
    The new algorithm for 6.0 sounds promising to improve this (with
    "set based propagation").<br>
    <br>
    Do you have any rule that has 2 accumulates in 1 rule?<br>
    That used to kill my statefull performance (3 times slower etc), but
    a recent experiment with 5.5 showed that that's no longer the case
    IIRC.<br>
    <br>
    <div class="moz-cite-prefix">Op 09-01-13 15:09, Ryan Crumley
      schreef:<br>
    </div>
    <blockquote
cite="mid:CAEbF3qPTrjQQDGsXznN-MeQvQuUbpvwxUd4aZf8QtJihpqc0Qg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hi,</div>
        <div><br>
        </div>
        <div>I am investigating performance of a Drools 5.4 stateful
          knowledge session. This session has about 200 rules, 200k
          facts and takes about 1 hour to run to completion. Looking at
          the profile there is a hotspot that consumes almost 65% of the
          cpu time: java.util.AbstractList.hashCode().</div>
        <div><br>
        </div>
        <div>Here is the full stack:&nbsp;</div>
        <div><br>
        </div>
        <div>&nbsp;
          &nbsp;com.company.rules.engine.Rule_Set_weights_08b44ce519a74b58ab3f85735b2987cbDefaultConsequenceInvoker.evaluate(KnowledgeHelper,
          WorkingMemory)</div>
        <div>
          &nbsp;
          &nbsp;com.company.rules.engine.Rule_Set_weights_08b44ce519a74b58ab3f85735b2987cbDefaultConsequenceInvokerGenerated.evaluate(KnowledgeHelper,
          WorkingMemory)</div>
        <div>&nbsp;
          &nbsp;com.company.rules.engine.Rule_Set_weights_08b44ce519a74b58ab3f85735b2987cb.defaultConsequence(KnowledgeHelper,
          List, FactHandle, GradingFact, FactHandle, ReportNode,
          FactHandle, WeightsHolder, FactHandle, Logger)</div>
        <div>&nbsp;
          &nbsp;org.drools.base.DefaultKnowledgeHelper.update(FactHandle,
          long)</div>
        <div>&nbsp; &nbsp;org.drools.common.NamedEntryPoint.update(FactHandle,
          Object, long, Activation)</div>
        <div>&nbsp; &nbsp;org.drools.common.NamedEntryPoint.update(FactHandle,
          Object, long, Activation)</div>
        <div>&nbsp;
&nbsp;org.drools.common.PropagationContextImpl.evaluateActionQueue(InternalWorkingMemory)</div>
        <div>&nbsp;
&nbsp;org.drools.reteoo.ReteooWorkingMemory$EvaluateResultConstraints.execute(InternalWorkingMemory)</div>
        <div>&nbsp;
          &nbsp;org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode$ActivitySource,
          LeftTuple, PropagationContext, InternalWorkingMemory,
          AccumulateNode$AccumulateMemory,
          AccumulateNode$AccumulateContext, boolean)</div>
        <div>&nbsp; &nbsp;org.drools.common.DefaultFactHandle.setObject(Object)</div>
        <div>&nbsp; &nbsp;java.util.AbstractList.hashCode()</div>
        <div><br>
        </div>
        <div>I believe the following clues can be extracted:</div>
        <div><br>
        </div>
        <div>- "Rule_Set_weights" was fired and a fact was modified
          (confirmed by examining the rule definition)</div>
        <div>- The fact modification caused the pre-conditions for other
          rules to be computed.</div>
        <div>- One of these rules has an accumulate condition that
          accumulates into an AbstractList.</div>
        <div>- This list is very very large. So large that looping
          through the elements in the list and aggregating the hashCode
          of individual elements dominates execution time (the
          individual element hashCode doesn't even show up in the
          profile&#8230; either its very fast or maybe its identify hashCode
          which the profiler might filter?).&nbsp;</div>
        <div>- Accumulate is either working on a large set of data or
          the same accumulate is evaluated many many times. &nbsp;</div>
        <div><br>
        </div>
        <div>Is my analysis correct? Are there clues that I am missing?&nbsp;</div>
        <div><br>
        </div>
        <div>
          I have 15 rules that use accumulate&#8230; However none accumulate
          with a result of List. Most accumulate using sum() and count()
          (result of Number). A few use collectSet(). A few more
          aggregate into a result with a custom type.</div>
        <div><br>
        </div>
        <div>A few other notes:&nbsp;</div>
        <div>- All accumulate conditions are the last condition in the
          WHEN clause.&nbsp;</div>
        <div>- I use agenda groups to separate fact processing into
          phases. Rules that accumulate are in a separate agenda group
          from rules that modify/insert facts that are used in
          accumulation. I hope this prevents the accumulate condition
          from being evaluated until all the rules that modify the facts
          accumulate needs are done firing. I suspect this may not be
          working as I expect. I haven't put together an example to
          investigate.&nbsp;</div>
        <div>- When accumulating into a set, the rule condition looks
          like this:</div>
        <div>&nbsp; &nbsp; $factName : Set() from accumulate( FactMatch( $field :
          field ), collectionSet( $field ) )</div>
        <div><br>
        </div>
        <div>How can I narrow down this further?&nbsp;</div>
        <div><br>
        </div>
        <div>Are there any general rules to follow to optimize use of
          accumulate in conditions?&nbsp;</div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div><br>
        </div>
        <div>Ryan</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>