Shoab Alam
Shoab Alam

Reputation: 279

Memory taken by drools Knowkedge session

I have the requirment of having knowledge base partitioned on per user basis. All the session needs to be in memory. In the first phase i have tested with 2000 session, which is taking up almost 750mb of heap memory, considering 5 rules in each session. Can somebody tell me how to determine the size of each session and reduce memory consumption as i need to scale the application to 10000 of user

Upvotes: 0

Views: 2045

Answers (2)

Sachin Verma
Sachin Verma

Reputation: 3802

It don't show the memory usage but this can help you to get knowledge of all rules and facts currently in runtime.

TO know rules:

ksession2.getKnowledgeBase().getKnowledgePackages().each {
            it.rules.each { log.debug "- rules are:"+it.name }
        }

for facts:

for (Object fact : ksession2.getObjects()) {
            sb2z.append (" Fact: " + fact.class.name);
        }

I use above scripted ways to get runtime objects info and use some JVM visualizer to know their size.

Upvotes: 0

Steve
Steve

Reputation: 9480

You just need to run your application with different numbers of concurrent sessions, plot a graph of sessions vs heap size and extrapolate. No special sauce I can think of relating to Drools specifically.

Key to this will be the number of facts in each session and the number of joins in your rules. You should read this section of the manual on "Cross Products", which explains how to reduce joins:

http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e941

Also, two questions you should consider:

  1. Is there a way in which you could refactor to use stateless sessions?
  2. Is there a way in which you can have a single session to cater for all users?

Unless you have huge volumes of facts to insert at the start of each user session, or your application is doing some kind of streaming event processing using Fusion, then you should be able to switch to stateless sessions without any serious performance impact.

Upvotes: 1

Related Questions