<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi, thanks for answering so quickly.<div><br></div><div>My ±2100 rules are grouped in 700 groups of 3 drools rules each, which are related to the same type of event i want to generate, like the following:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">rule "event1 reset" no-loop salience 9 activation-group "event1_group" lock-on-active agenda-group "a3ce4a97-13d8-4bec-a9ab-5625fcd0f105"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>$source : SourceBO(&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>ciUUID == "3938adc4-246d-43f3-b606-da4c3f09d49b",</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$object : object,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$CI : ciUUID,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$sourceUUID : sourceUUID)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>$value1 : SourceValueBO ( valueName == "VALUE1", numericValue &lt; 90 )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>eval (checkMayReset($source, "fb95632f-fac9-4359-9d7c-dc38d3e48e20", $CI, $object))</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>modify ($value1) { setConditionValue(90) };</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>resetSource($source, "fb95632f-fac9-4359-9d7c-dc38d3e48e20", $CI, $object, "event_version", "event_text", Arrays.asList($value1));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">end</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">rule "event1 fire" no-loop salience 6 activation-group "event1_group"&nbsp;lock-on-active agenda-group "a3ce4a97-13d8-4bec-a9ab-5625fcd0f105"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>$source : SourceBO(&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>ciUUID == "3938adc4-246d-43f3-b606-da4c3f09d49b",</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$object : object,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$CI : ciUUID,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$sourceUUID : sourceUUID )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>$value1: SourceValueBO ( valueName == "VALUE1", numericValue &gt; 90 )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>modify ($value1) { setConditionValue(90) };</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>FireCondition $start = new FireCondition("repeat", 0, "duration", "0s");</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>addToActivationQueue($source, "fb95632f-fac9-4359-9d7c-dc38d3e48e20", $CI, $object, $start, null, "event_version", "event_text", Arrays.asList($value1));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>retract($source);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">end</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; min-height: 12px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">rule "event1 clear" no-loop salience 5 activation-group "event1_group" lock-on-active agenda-group "a3ce4a97-13d8-4bec-a9ab-5625fcd0f105"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>when</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>$source : SourceBO(</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>ciUUID == "3938adc4-246d-43f3-b606-da4c3f09d49b",</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$object : object,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$CI : ciUUID,&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                        </span>$sourceUUID : sourceUUID)&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>then</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>clearActivationQueue($source, "fb95632f-fac9-4359-9d7c-dc38d3e48e20", $CI, $object);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Monaco; ">end</div></div><div><br><div><div>So, i'l try to explain briefly:</div><div>* The reset rule evaluates 2 patterns and one condition in a static method available via "import function". As a consequence, it modifies the SourceValueBO object and call's the reset function which is another static method.</div><div>* The fire rule is very similar to the reset rule, the difference being that the value threshold is different (usually the opposite)</div><div>* The clear rule is like an "else" to the two above. I want it to fire in case it didn't fall for either one of reset and fire rules.</div><div><br></div><div>The activation group assures that only one of these rules is fired each time i call session.fireAllRules(). And the agenda-group allows me to stack some rules above others, according to the type of facts i insert into memory.</div><div>Everything seems in place and it works as intended, the thing is i might be dealing with *lots* of events (event1, event2, etc...) and lots of different UUID's which results in a very large DRL file. For instance, if i have 700 events (event1, event ...event700), i get 2100 drools rules (event1 reset, event1 fire, event1 clear ... event700 reset, event700 fire, event700 clear) and over 300MB in consumed memory.</div><div><br></div><div>Perhaps if i took another approach? or some performance tunning, i don't know. Where can i improve this memory hogging?</div><div>_ miguel</div><div><br></div><div><br></div><div><br></div><div><br></div><div>On 31 Mar 2010, at 06:53, Wolfgang Laun wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>The figures (+300MB) you quote are frightening, and it would be *very*<br>interesting to learn what sort of rules causes this excessive amount<br>of heap usage. Could you post typical patterns - if they are<br>generated, there ought to be - and guestimates w.r,t, their relative<br>frequencies?<br><br>-W<br><br><br>On 3/30/10, miguel machado &lt;<a href="mailto:mls.machado@gmail.com">mls.machado@gmail.com</a>&gt; wrote:<br><blockquote type="cite">hi again,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On 30 Mar 2010, at 18:32, Edson Tirelli &lt;<a href="mailto:ed.tirelli@gmail.com">ed.tirelli@gmail.com</a>&gt; wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> &nbsp;&nbsp;I am not sure I understand what you are doing when you say:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">Every X seconds I collect the available facts and call fireAllRules() +<br></blockquote></blockquote><blockquote type="cite">dispose(), **always within the same session**.<br></blockquote><blockquote type="cite">(emphasis is mine)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">i meant that i keep using the same object, i just create one stateful<br></blockquote><blockquote type="cite">session throughout the program execution.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> &nbsp;&nbsp;Compilation indeed uses more memory, but you can compile once and reuse<br></blockquote><blockquote type="cite">the kbase.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">exactly, i'm doing that, but it's a +700 rule file and its taking too much<br></blockquote><blockquote type="cite">memory. Is there anything i can do to push it down a little bit? i wouldn't<br></blockquote><blockquote type="cite">mind slowing it down to reduce memory footprint.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Also, if you are calling dispose, I guess you are running stateful sessions.<br></blockquote><blockquote type="cite">Maybe you can give us a more detailed description of your<br></blockquote><blockquote type="cite">session/data/application lifecycle?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Sure, i'll try. So i have this thread which initializes by reading the rule<br></blockquote><blockquote type="cite">base from a drl file. It then creates a stateful session from it and enters<br></blockquote><blockquote type="cite">a lifecycle in which it goes to sleep and only when some other thread wakes<br></blockquote><blockquote type="cite">it up, it collects and inserts some facts (usually 2,3 or 4..) into the<br></blockquote><blockquote type="cite">session and fire all rules. It's basically this. What i'm very concerned<br></blockquote><blockquote type="cite">about is the amount of RAM memory the whole program is consuming. I must<br></blockquote><blockquote type="cite">find a way to reduce some of it, because the rule file is being prepared by<br></blockquote><blockquote type="cite">an external program and i have no control over the number of rules i might<br></blockquote><blockquote type="cite">get. If i test it with a little over 700 rules, it reaches +300Mb which is a<br></blockquote><blockquote type="cite">lot.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Maybe the rules are too complex? Shall i try to make them simpler (how)?<br></blockquote><blockquote type="cite">what are the big memory hogs when it comes to loading a DRL file to the<br></blockquote><blockquote type="cite">knowledge base? From what i've been testing, it doesn't even matter which<br></blockquote><blockquote type="cite">rules you will actually need, it just loads the entire DRL file with no<br></blockquote><blockquote type="cite">respect to the future activations, am i right? Is there any other aspect i<br></blockquote><blockquote type="cite">should take in mind or maybe other approach?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_ miguel<br></blockquote><blockquote type="cite"><br></blockquote>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></div></blockquote></div><br></div></body></html>