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

Greg Barton greg_barton at yahoo.com
Sat Aug 8 07:22:52 EDT 2009


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
> 


      



More information about the rules-dev mailing list