Hi there,

First of all, thank you for your detailed and quick response. Next...

2010/3/31 Edson Tirelli <ed.tirelli@gmail.com>

    Miguel,

    First we need to understand where is this memory spent. Drools externalizes the actual rule compilation to a java compiler (JDT or Janino) and I would not be surprised if compiling 2100 rules would consume more than 300Mb **during compilation**. I don't think that after compiling, the application will continue to use that amount of memory just because of rules, although if you have many facts being inserted into your session, it obviously will drive consumption up.

I usually load into memory 2~4 facts each time, very small objects. I then "fire all rules" and immediately retract and dispose.
 

    So, some questions:

1. Do you use one KnowledgeBuilder to compile all your rule files or do you use one KnowledgeBuilder per file?

Just one, declared as a static variable.
 
2. How much memory is your application using during this step, where you add resources to your knowledgeBuilder(s)?

Its taking about ±20 MB just before it reads the DRL file, it then takes 5~10s for loading rules into memory and immediately after that line its taking +300MB.. kinda stabilizes afterwards.
 
3. After compiling your knowledge packages, did you tried to force a GC to check how much memory it continues to use?

Just tested that, it barely makes a difference :-/ (less than 5MB saved)
 
4. Are you adding all rules to the same KnowledgeBase or using one kbase per set of rules? How much memory are you consuming in this step?

Most of the time, i've been testing with only one rule file with +2100 rules and for that i create a single knowledge base, from which i create the ksession. However, the whole system i'm developing has another component of event analysis so eventually i'll be testing two separate threads doing similar things but on different DRL files. I suppose i'll be using two kbase's, one for each file...

This is the step where memory usage increases dramatically:

 
kbuilder.add( ResourceFactory.newFileSystemResource( fileName ), ResourceType.DRL );
 

5. Did you tried compiling it once, generating the kbase and serializing it to a file, and then, instead of recompiling everything, just deserialize the file into memory and using it? How much memory it consumes when you deserialize from a file?

Not sure what you mean there, is it this: http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/html_single/index.html#d0e1070 ? if so, yes, i've tried it and noticed no difference at all, was i supposed to?
 

   Knowing the answer to the above questions will help to determine if you have a problem and how to work around it or fix it.

thanks for your help so far. Any help is very much appreciated.

_ miguel


--
"To understand what is recursion you must first understand recursion"