Skip to: Site menu | Main content

Drools

Java Rules Engine

Hot Spots Print

Hot Spots

It makes no sense to start optimizing methods until we know which methods are bearing the brunt of the load during rule execution. With this in mind and with Mark Proctor's expert tutelage, I whipped up a comprehensive event monitor aspect that caches the number of times methods get called at runtime. I set it to monitor all methods in the org.drools.spi, org.drools.rule and org.drools.reteoo packages.

With this tool we can track which parts of the engine bear the most burden, and focus our optimization efforts there. If people like, I can check the new aspect and the monitor class into CVS. For the moment, however, I'll post the results of my tests. Below is a printout of all the methods used in the Fibonacci Example, arranged in descending order according to the number of times they were called.

(rest of maven fibonacci output is trimmed)

    [java] == Monitor Listings ==
    [java] org.drools.rule.Declaration.hashCode() : 66941
    [java] org.drools.reteoo.FactHandleImpl.hashCode() : 30858
    [java] org.drools.reteoo.TupleKey.get(Declaration) : 21518
    [java] org.drools.reteoo.TupleKey.hashCode() : 19356
    [java] org.drools.reteoo.TupleSet.Itr.hasNext() : 15867
    [java] org.drools.reteoo.ReteTuple.getKey() : 14102
    [java] org.drools.reteoo.TupleSet.Itr.next() : 14050
    [java] org.drools.reteoo.FactHandleImpl.equals(Object) : 11049
    [java] org.drools.reteoo.TupleKey.getDeclarations() : 10711
    [java] org.drools.reteoo.TupleKey.containsAll(TupleKey) : 10711
    [java] org.drools.reteoo.ReteTuple.getWorkingMemory() : 7886
    [java] org.drools.rule.Declaration.getIdentifier() : 4994
    [java] org.drools.rule.Declaration.getObjectType() : 4974
    [java] org.drools.reteoo.ReteTuple.get(Declaration) : 4962
    [java] org.drools.reteoo.TupleSource.getTupleSink() : 4364
    [java] org.drools.reteoo.ReteTuple.getRule() : 3542
    [java] org.drools.reteoo.TupleSource.propagateRetractTuples(TupleKey, WorkingMemoryImpl) : 3312
    [java] org.drools.reteoo.ReteTuple.putAll(ReteTuple) : 2938
    [java] org.drools.reteoo.TupleKey.putAll(TupleKey) : 2938
    [java] org.drools.reteoo.WorkingMemoryImpl.getListeners() : 2419
    [java] org.drools.reteoo.TupleKey() : 2357
    [java] org.drools.reteoo.ReteTuple.getDeclarations() : 2172
    [java] org.drools.reteoo.WorkingMemoryImpl.getApplicationDataMap() : 2172
    [java] org.drools.reteoo.ConditionNode.getCondition() : 2073
    [java] org.drools.reteoo.ReteTuple(WorkingMemory, Rule) : 2069
    [java] org.drools.reteoo.WorkingMemoryImpl.getAgenda() : 1961
    [java] org.drools.reteoo.TerminalNode.getRule() : 1960
    [java] org.drools.reteoo.Agenda.removeFromAgenda(TupleKey, Rule) : 1860
    [java] org.drools.reteoo.TerminalNode.retractTuples(TupleKey, WorkingMemoryImpl) : 1860
    [java] org.drools.reteoo.TupleSet.addTuple(ReteTuple) : 1819
    [java] org.drools.reteoo.TupleSet.iterator() : 1817
    [java] org.drools.reteoo.TupleSet.Itr(Map) : 1817
    [java] org.drools.reteoo.TupleSet.Itr.remove() : 1766
    [java] org.drools.reteoo.JoinTuple(ReteTuple, ReteTuple) : 1469
    [java] org.drools.reteoo.JoinMemory.attemptJoin(ReteTuple, ReteTuple) : 1469
    [java] org.drools.reteoo.JoinMemory.getJoinDeclarationIterator() : 1469
    [java] org.drools.reteoo.JoinMemory.retractTuples(TupleKey, Iterator) : 970
    [java] org.drools.reteoo.ConditionNode.retractTuples(TupleKey, WorkingMemoryImpl) : 967
    [java] org.drools.reteoo.TupleKey.put(Declaration, FactHandle) : 888
    [java] org.drools.reteoo.ParameterNode.getDeclaration() : 888
    [java] org.drools.reteoo.JoinNodeInput.getJoinNode() : 684
    [java] org.drools.reteoo.WorkingMemoryImpl.getJoinMemory(JoinNode) : 684
    [java] org.drools.reteoo.TupleSource.propagateModifyTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 648
    [java] org.drools.reteoo.JoinMemory.getRightTuples() : 634
    [java] org.drools.reteoo.AgendaItem.getRule() : 634
    [java] org.drools.reteoo.JoinMemory.getLeftTuples() : 634
    [java] org.drools.reteoo.ReteTuple(WorkingMemory, Rule, Declaration, FactHandle, Object) : 600
    [java] org.drools.reteoo.ReteTuple.putKeyColumn(Declaration, FactHandle, Object) : 600
    [java] org.drools.reteoo.ReteTuple.putColumn(Declaration, Object) : 600
    [java] org.drools.reteoo.JoinNodeInput.retractTuples(TupleKey, WorkingMemoryImpl) : 485
    [java] org.drools.reteoo.JoinNode.retractTuples(TupleKey, WorkingMemoryImpl) : 485
    [java] org.drools.reteoo.JoinMemory.retractTuples(TupleKey) : 485
    [java] org.drools.reteoo.ConditionNode.modifyTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 451
    [java] org.drools.reteoo.TupleSet.size() : 451
    [java] org.drools.reteoo.TupleSource.propagateAssertTuple(ReteTuple, WorkingMemoryImpl) : 404
    [java] org.drools.reteoo.ConditionNode.assertTuple(ReteTuple, WorkingMemoryImpl) : 302
    [java] org.drools.reteoo.TupleSet() : 302
    [java] org.drools.reteoo.ParameterNode.modifyObject(FactHandle, Object, WorkingMemoryImpl) : 300
    [java] org.drools.reteoo.TupleSet(ReteTuple) : 300
    [java] org.drools.reteoo.TupleSet(int) : 300
    [java] org.drools.reteoo.ParameterNode.assertObject(FactHandle, Object, WorkingMemoryImpl) : 300
    [java] org.drools.reteoo.ParameterNode.retractObject(FactHandle, WorkingMemoryImpl) : 288
    [java] org.drools.reteoo.TupleKey(Declaration, FactHandle) : 288
    [java] org.drools.reteoo.TupleKey.containsRootFactHandle(FactHandle) : 242
    [java] org.drools.reteoo.ReteTuple.dependsOn(FactHandle) : 242
    [java] org.drools.reteoo.Agenda.isEmpty() : 199
    [java] org.drools.reteoo.JoinMemory.attemptJoin(ReteTuple, Iterator) : 199
    [java] org.drools.reteoo.AgendaItem.getKey() : 191
    [java] org.drools.reteoo.TupleSet.addAllTuples(Set) : 149
    [java] org.drools.reteoo.JoinNodeInput.modifyTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 149
    [java] org.drools.reteoo.TupleSet.getTuples() : 149
    [java] org.drools.reteoo.JoinMemory.modifyTuples(FactHandle, TupleSet, TupleSet, TupleSet, JoinNode, WorkingMemoryImpl) : 149
    [java] org.drools.reteoo.TupleSet.addAllTuples(TupleSet) : 149
    [java] org.drools.reteoo.ObjectTypeNode.getObjectType() : 149
    [java] org.drools.reteoo.ObjectTypeNode.getParameterNodeIterator() : 148
    [java] org.drools.reteoo.RuleBaseImpl.getRete() : 148
    [java] org.drools.reteoo.Rete.getObjectTypeNodeIterator() : 148
    [java] org.drools.rule.Rule.getConsequence() : 103
    [java] org.drools.rule.Rule.getSalience() : 103
    [java] org.drools.reteoo.AgendaItem(ReteTuple, Rule) : 100
    [java] org.drools.reteoo.Agenda.addToAgenda(ReteTuple, Rule) : 100
    [java] org.drools.rule.Rule.getDuration() : 100
    [java] org.drools.reteoo.JoinMemory.modifyLeftTuples(FactHandle, TupleSet, JoinNode, WorkingMemoryImpl) : 99
    [java] org.drools.reteoo.JoinNode.modifyLeftTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 99
    [java] org.drools.reteoo.Agenda.fireNextItem() : 99
    [java] org.drools.reteoo.AgendaItem.getTuple() : 99
    [java] org.drools.reteoo.AgendaItem.fire(WorkingMemory) : 99
    [java] org.drools.reteoo.ReteTuple.getFactHandleForObject(Object) : 98
    [java] org.drools.reteoo.TerminalNode.assertTuple(ReteTuple, WorkingMemoryImpl) : 52
    [java] org.drools.reteoo.RuleBaseImpl.assertObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.JoinNode.assertRightTuple(ReteTuple, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.WorkingMemoryImpl.assertObject(Object) : 50
    [java] org.drools.reteoo.WorkingMemoryImpl.containsObject(FactHandle) : 50
    [java] org.drools.reteoo.Rete.assertObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.ObjectTypeNode.modifyObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.WorkingMemoryImpl.putObject(FactHandle, Object) : 50
    [java] org.drools.reteoo.FactHandleImpl(long) : 50
    [java] org.drools.reteoo.WorkingMemoryImpl.newFactHandle() : 50
    [java] org.drools.reteoo.JoinMemory.modifyRightTuples(FactHandle, TupleSet, JoinNode, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.RuleBaseImpl.modifyObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.JoinNodeInput.assertTuple(ReteTuple, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.DefaultFactHandleFactory.newFactHandle() : 50
    [java] org.drools.reteoo.ObjectTypeNode.assertObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.JoinNode.modifyRightTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.Rete.modifyObject(FactHandle, Object, WorkingMemoryImpl) : 50
    [java] org.drools.reteoo.JoinMemory.getLeftTupleIterator() : 50
    [java] org.drools.reteoo.WorkingMemoryImpl.modifyObject(FactHandle, Object) : 50
    [java] org.drools.reteoo.JoinMemory.addRightTuple(JoinNode, ReteTuple) : 50
    [java] org.drools.reteoo.RuleBaseImpl.retractObject(FactHandle, WorkingMemoryImpl) : 48
    [java] org.drools.reteoo.ObjectTypeNode.retractObject(FactHandle, WorkingMemoryImpl) : 48
    [java] org.drools.reteoo.Rete.retractObject(FactHandle, WorkingMemoryImpl) : 48
    [java] org.drools.reteoo.WorkingMemoryImpl.retractObject(FactHandle) : 48
    [java] org.drools.reteoo.Agenda.modifyAgenda(FactHandle, TupleSet, Rule) : 48
    [java] org.drools.reteoo.WorkingMemoryImpl.getObject(FactHandle) : 48
    [java] org.drools.reteoo.TerminalNode.modifyTuples(FactHandle, TupleSet, WorkingMemoryImpl) : 48
    [java] org.drools.reteoo.ParameterNode.getTupleDeclarations() : 40
    [java] org.drools.reteoo.ConditionNode.getTupleDeclarations() : 32
    [java] org.drools.rule.Declaration.equals(Object) : 25
    [java] org.drools.reteoo.Builder.matches(Declaration[], Set) : 22
    [java] org.drools.reteoo.Builder.matches(Condition, Set) : 22
    [java] org.drools.reteoo.TupleSource() : 18
    [java] org.drools.reteoo.TupleSource.setTupleSink(TupleSink) : 18
    [java] org.drools.rule.Rule.getAllDeclarations() : 14
    [java] org.drools.reteoo.Builder.findMatchingTupleSourceForCondition(Condition, Set) : 13
    [java] org.drools.rule.Rule.addCondition(Condition) : 10
    [java] org.drools.reteoo.ConditionNode(TupleSource, Condition) : 10
    [java] org.drools.rule.Rule.getConditions() : 8
    [java] org.drools.rule.Rule.getParameterDeclarations() : 8
    [java] org.drools.reteoo.Builder.getRete() : 7
    [java] org.drools.reteoo.JoinNode.getTupleDeclarations() : 6
    [java] org.drools.reteoo.JoinNode.getLeftInput() : 6
    [java] org.drools.reteoo.Rete.getOrCreateObjectTypeNode(ObjectType) : 6
    [java] org.drools.reteoo.Builder.createJoinNodes(Set) : 6
    [java] org.drools.reteoo.Builder.attachExtractions(Set, Set) : 6
    [java] org.drools.reteoo.Builder.attachConditions(List, Set) : 6
    [java] org.drools.rule.Declaration.setObjectType(ObjectType) : 6
    [java] org.drools.rule.Declaration(String) : 6
    [java] org.drools.reteoo.Rete.getObjectTypeNode(ObjectType) : 6
    [java] org.drools.rule.Rule.addParameterDeclaration(Declaration) : 6
    [java] org.drools.reteoo.ObjectTypeNode.addParameterNode(ParameterNode) : 6
    [java] org.drools.reteoo.JoinNode.getRightInput() : 6
    [java] org.drools.rule.Rule.addDeclaration(Declaration) : 6
    [java] org.drools.reteoo.ParameterNode(Rule, ObjectTypeNode, Declaration) : 6
    [java] org.drools.reteoo.TerminalNode(TupleSource, Rule) : 4
    [java] org.drools.reteoo.Builder.addRule(RuleSet, Rule) : 4
    [java] org.drools.reteoo.Builder.canBeJoined(TupleSource, TupleSource) : 4
    [java] org.drools.rule.Rule.getExtractions() : 4
    [java] org.drools.rule.Rule(String) : 4
    [java] org.drools.reteoo.JoinNodeInput(JoinNode, int) : 4
    [java] org.drools.rule.Rule.getName() : 4
    [java] org.drools.reteoo.Builder.createParameterNodes(Rule) : 4
    [java] org.drools.rule.Rule.setConsequence(Consequence) : 4
    [java] org.drools.rule.RuleSet.addRule(Rule) : 4
    [java] org.drools.rule.RuleSet.containsRule(String) : 4
    [java] org.drools.rule.Rule.checkValidity() : 4
    [java] org.drools.reteoo.JoinNode(TupleSource, TupleSource) : 2
    [java] org.drools.reteoo.JoinMemory(JoinNode) : 2
    [java] org.drools.reteoo.JoinNode.determineCommonDeclarations() : 2
    [java] org.drools.reteoo.JoinNode.getRightNodeInput() : 2
    [java] org.drools.rule.Rule.setSalience(int) : 2
    [java] org.drools.reteoo.JoinNode.getCommonDeclarations() : 2
    [java] org.drools.reteoo.Builder.joinForCondition(List, Set) : 2
    [java] org.drools.reteoo.JoinNode.getLeftNodeInput() : 2
    [java] org.drools.reteoo.Builder.joinArbitrary(Set) : 2
    [java] org.drools.rule.RuleSet.getRules() : 1
    [java] org.drools.reteoo.Builder.setConflictResolver(ConflictResolver) : 1
    [java] org.drools.reteoo.ObjectTypeNode(ObjectType) : 1
    [java] org.drools.reteoo.WorkingMemoryImpl.fireAllRules() : 1
    [java] org.drools.reteoo.WorkingMemoryImpl.initializeFactHandleFactory() : 1
    [java] org.drools.reteoo.DroolsEventModel() : 1
    [java] org.drools.reteoo.RuleBaseImpl(Rete, RuleSet[], ConflictResolver) : 1
    [java] org.drools.reteoo.Rete.addObjectTypeNode(ObjectTypeNode) : 1
    [java] org.drools.reteoo.Builder.addRuleSet(RuleSet) : 1
    [java] org.drools.reteoo.Builder() : 1
    [java] org.drools.reteoo.RuleBaseImpl.newWorkingMemory() : 1
    [java] org.drools.reteoo.DefaultFactHandleFactory() : 1
    [java] org.drools.reteoo.Builder.buildRuleBase() : 1
    [java] org.drools.reteoo.RuleBaseImpl.getConflictResolver() : 1
    [java] org.drools.rule.RuleSet(String) : 1
    [java] org.drools.reteoo.Rete() : 1
    [java] org.drools.reteoo.Agenda(WorkingMemory, ConflictResolver) : 1
    [java] org.drools.reteoo.WorkingMemoryImpl(RuleBaseImpl, ConflictResolver) : 1
    [java] == End of Monitor Listings ==
BUILD SUCCESSFUL
Total time: 24 seconds
Finished at: Sun Jun 20 20:19:30 PDT 2004