[rules-dev] Why is this DRL twice as slow?

Edson Tirelli tirelli at post.com
Sat Aug 8 08:05:46 EDT 2009


    Greg is in the right direction. When you have:

when
    Pattern1()
    Pattern2()
then
   ...

   Anytime Pattern1 change, Pattern2 beta constraints must be reevaluated.
The problem in your case is that both patterns are accumulates, so they are
heavier by themselves AND everytime the first one changes, the second must
fully recalculate.

   []s
   Edson

2009/8/8 Greg Barton <greg_barton at yahoo.com>

>
> As I understand it, the from keyword is not optimized in the way that it's
> output is not indexed.  Therefore if the set of objects matched changes it
> must rerun.  So when you have the two rules, "hardConstraintsBroken" is
> reevaluated when you change the hard constraints, and
> "softConstraintsBroken" is reevaluated when you change the soft constraints.
>  When there's just the one rule, it's reevaluated when either the hard or
> soft constraints changed, but BOTH accumulate expressions are evaluated
> every time.  Thus, 2x the evaluation time.
>
> --- On Sat, 8/8/09, Geoffrey De Smet <ge0ffrey.spam at gmail.com> wrote:
>
> > From: Geoffrey De Smet <ge0ffrey.spam at gmail.com>
> > Subject: [rules-dev] Why is this DRL twice as slow?
> > To: rules-dev at lists.jboss.org
> > Date: Saturday, August 8, 2009, 5:46 AM
> > Hi guys,
> >
> > I've run some experiments on the DRL's used in the drools
> > solver
> > examination example to see how the DRL affects
> > performance.
> >
> > In one experiment, I merged 2 rules into 1 rule:
> >
> > I changed this DRL part of examinationScoreRules.drl:
> >
> > rule "hardConstraintsBroken"
> >          salience -1
> >      when
> >          $hardTotal :
> > Number() from accumulate(
> >
> >    IntConstraintOccurrence(constraintType ==
> >
> > ConstraintType.NEGATIVE_HARD, $weight : weight),
> >
> >    sum($weight)
> >          );
> >      then
> >
> >    scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());
> > end
> >
> > rule "softConstraintsBroken"
> >          salience -1
> >      when
> >          $softTotal :
> > Number() from accumulate(
> >
> >    IntConstraintOccurrence(constraintType ==
> >
> > ConstraintType.NEGATIVE_SOFT, $weight : weight),
> >
> >    sum($weight)
> >          );
> >      then
> >
> >    scoreCalculator.setSoftConstraintsBroken($softTotal.intValue());
> > end
> >
> >
> >
> > into this DRL part:
> >
> > rule "constraintsBroken"
> >          salience -1
> >      when
> >          $hardTotal :
> > Number() from accumulate(
> >
> >    IntConstraintOccurrence(constraintType ==
> >
> > ConstraintType.NEGATIVE_HARD, $weight : weight),
> >
> >    sum($weight)
> >          );
> >          $softTotal :
> > Number() from accumulate(
> >
> >    IntConstraintOccurrence(constraintType ==
> >
> > ConstraintType.NEGATIVE_SOFT, $weight : weight),
> >
> >    sum($weight)
> >          );
> >      then
> >
> >    scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());
> >
> >    scoreCalculator.setSoftConstraintsBroken($softTotal.intValue());
> > end
> >
> >
> > Now the performance for a 100 steps when from 71s to 172s,
> > so it more
> > then doubled.
> > All other code stayed the same and the output (except for
> > the times) is
> > exactly the same.
> > What can explain this loss in performance?
> >
> > --
> > With kind regards,
> > Geoffrey De Smet
> >
> > _______________________________________________
> > rules-dev mailing list
> > rules-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-dev
> >
>
>
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>



-- 
 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-dev/attachments/20090808/450132a0/attachment-0001.html 


More information about the rules-dev mailing list