[rules-users] Performance and Memory Utilization - StatefulKnowledgeSession

HonorGod jagadeesh.motamarri at barclayscapital.com
Thu Feb 4 12:38:53 EST 2010


I have over million rows of data that are stored in a fact model. I have to
apply 2 sets of rules [coming from 2 decision tables - cannot combine them
for a specific reason] on each fact model.

I have created static knowledgebases and stored them in cache so that they
can be used when ever new StatefulKnowledgeSessions are required. 

This is how I am doing it - 

Iterating over the fact model one after the other and pass them to the
method that applies rules - 

 public int applyRules(MyModel model) {
        int noOfRulesFired  = 0 ;
        StatefulKnowledgeSession kSession =
((KnowledgeBase)DroolsKnowledgeBaseManager.getInstance().knowledgeBases.get("FirstSetOfRules")).newStatefulKnowledgeSession()
;
        kSession.insert(model);
        noOfRulesFired = kSession.fireAllRules();
    
        if( noOfRulesFired >= 1  ) {
        kSession =
((KnowledgeBase)DroolsKnowledgeBaseManager.getInstance().knowledgeBases.get("SecondSetOfRules")).newStatefulKnowledgeSession()
;
            
        kSession.insert(model);
        kSession.insert(this);
        noOfRulesFired +=kSession.fireAllRules();
        }
        kSession.dispose() ;
        return noOfRulesFired ;
    }

Is this good approach? How can I reuse StatefulKnowledgeSessions so that I
can insert my fact models one at a time and fire rules. Creating new
StatefulKnowledgeSession for every fact model is consuming lot of memory and
even though dispose() is called before existing method - GC might not clean
it instently.

Please assist [I am in middle of UAT and started to notice that memory
consumption is too high] .

Thanks
-- 
View this message in context: http://n3.nabble.com/Performance-and-Memory-Utilization-StatefulKnowledgeSession-tp187463p187463.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list