[rules-dev] Why is this DRL twice as slow? Why is calculationg from scratch faster?
Geoffrey De Smet
ge0ffrey.spam at gmail.com
Sat Aug 8 08:43:36 EDT 2009
So I tried this "query from scratch each time" experiment:
query "hardConstraintsBroken"
constraintOccurrence : IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD)
end
query "softConstraintsBroken"
constraintOccurrence : IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_SOFT)
end
With this java code:
int hard = 0;
QueryResults results =
workingMemory.getQueryResults("hardConstraintsBroken");
for (QueryResult result : results) {
IntConstraintOccurrence constraintOccurrence =
(IntConstraintOccurrence) result.get("constraintOccurrence");
hard += constraintOccurrence.getWeight();
}
int soft = 0;
results = workingMemory.getQueryResults("softConstraintsBroken");
for (QueryResult result : results) {
IntConstraintOccurrence constraintOccurrence =
(IntConstraintOccurrence) result.get("constraintOccurrence");
soft += constraintOccurrence.getWeight();
}
That takes 118s.
So it's clearly faster than the merged rule DRL!
It's not faster than the original accumulate DRL.
- original DRL: 71s
- query from scratch each time: 118s
- merged rule DRL: 172s
So calculating everything from scratch each time (and fetching it from
the QueryResult Map) is faster than using 2 accumulate.
With kind regards,
Geoffrey De Smet
Geoffrey De Smet schreef:
> 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?
>
More information about the rules-dev
mailing list