I can only offer a few hints:<br><br>Factor out all code that can be done in one of the called methods, e.g., in<br>  resetSource( ..., Arrays.asList($value1));<br>Here, the Arrays.asList() should be done in resetSource().<br>
<br>Avoid multiple bindings. If you call<br>  resetSource( $source,....)<br>or<br>  checkMayReset( $source,...)<br>the additional parameters $object and <span style="white-space: pre;"></span>$CI can be retrieved within resetSource().<br>
<br>The funny String literals are the one thing that are strikingly different from what you usually see in rules. String literals cost for each occurrence unless you intern strings using javal.lang.String.intern(). (I haven&#39;t tried whether Drools would accept that instead.) But calculating the raw cost as (46 chars*2 bytes/char+20 bytes)*10 times * 700 rule triples  only accounts for 0.8MB, so this alone isn&#39;t the culprit. <br>
<br>-W<br><br><br><div class="gmail_quote">2010/3/31 Miguel Machado <span dir="ltr">&lt;<a href="mailto:mls.machado@gmail.com">mls.machado@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="">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: 0px; min-height: 12px;"><br></div><div style="margin: 0px;">rule &quot;event1 reset&quot; no-loop salience 9 activation-group &quot;event1_group&quot; lock-on-active agenda-group &quot;a3ce4a97-13d8-4bec-a9ab-5625fcd0f105&quot;</div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span>when</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>$source : SourceBO( </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>ciUUID == &quot;3938adc4-246d-43f3-b606-da4c3f09d49b&quot;,</div>
<div style="margin: 0px;"><span style="white-space: pre;">                        </span>$object : object, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$CI : ciUUID, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$sourceUUID : sourceUUID)</div>
<div style="margin: 0px;"><span style="white-space: pre;">                </span>$value1 : SourceValueBO ( valueName == &quot;VALUE1&quot;, numericValue &lt; 90 )</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>eval (checkMayReset($source, &quot;fb95632f-fac9-4359-9d7c-dc38d3e48e20&quot;, $CI, $object))</div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span>then</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>modify ($value1) { setConditionValue(90) };</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>resetSource($source, &quot;fb95632f-fac9-4359-9d7c-dc38d3e48e20&quot;, $CI, $object, &quot;event_version&quot;, &quot;event_text&quot;, Arrays.asList($value1));</div>
<div style="margin: 0px;">end</div><div style="margin: 0px; min-height: 12px;"><br></div><div style="margin: 0px;">rule &quot;event1 fire&quot; no-loop salience 6 activation-group &quot;event1_group&quot; lock-on-active agenda-group &quot;a3ce4a97-13d8-4bec-a9ab-5625fcd0f105&quot;</div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span>when</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>$source : SourceBO( </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>ciUUID == &quot;3938adc4-246d-43f3-b606-da4c3f09d49b&quot;,</div>
<div style="margin: 0px;"><span style="white-space: pre;">                        </span>$object : object, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$CI : ciUUID, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$sourceUUID : sourceUUID )</div>
<div style="margin: 0px;"><span style="white-space: pre;">                </span>$value1: SourceValueBO ( valueName == &quot;VALUE1&quot;, numericValue &gt; 90 )</div><div style="margin: 0px;"><span style="white-space: pre;">        </span>then</div>
<div style="margin: 0px;"><span style="white-space: pre;">                </span>modify ($value1) { setConditionValue(90) };</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>FireCondition $start = new FireCondition(&quot;repeat&quot;, 0, &quot;duration&quot;, &quot;0s&quot;);</div>
<div style="margin: 0px;"><span style="white-space: pre;">                </span>addToActivationQueue($source, &quot;fb95632f-fac9-4359-9d7c-dc38d3e48e20&quot;, $CI, $object, $start, null, &quot;event_version&quot;, &quot;event_text&quot;, Arrays.asList($value1));</div>
<div style="margin: 0px;"><span style="white-space: pre;">                </span>retract($source);</div><div style="margin: 0px;">end</div><div style="margin: 0px; min-height: 12px;"><br></div><div style="margin: 0px;">rule &quot;event1 clear&quot; no-loop salience 5 activation-group &quot;event1_group&quot; lock-on-active agenda-group &quot;a3ce4a97-13d8-4bec-a9ab-5625fcd0f105&quot;</div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span>when</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>$source : SourceBO(</div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>ciUUID == &quot;3938adc4-246d-43f3-b606-da4c3f09d49b&quot;,</div>
<div style="margin: 0px;"><span style="white-space: pre;">                        </span>$object : object, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$CI : ciUUID, </div><div style="margin: 0px;"><span style="white-space: pre;">                        </span>$sourceUUID : sourceUUID) </div>
<div style="margin: 0px;"><span style="white-space: pre;">        </span>then</div><div style="margin: 0px;"><span style="white-space: pre;">                </span>clearActivationQueue($source, &quot;fb95632f-fac9-4359-9d7c-dc38d3e48e20&quot;, $CI, $object);</div>
<div style="margin: 0px;">end</div></div><div><br><div><div>So, i&#39;l try to explain briefly:</div><div>* The reset rule evaluates 2 patterns and one condition in a static method available via &quot;import function&quot;. As a consequence, it modifies the SourceValueBO object and call&#39;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 &quot;else&quot; to the two above. I want it to fire in case it didn&#39;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&#39;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&#39;t know. Where can i improve this memory hogging?</div><div>_ miguel</div><div><div></div><div class="h5"><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></div></div><blockquote type="cite"><div><div><div></div><div class="h5">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" target="_blank">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" target="_blank">ed.tirelli@gmail.com</a>&gt; wrote:<br></blockquote><blockquote type="cite"><br></blockquote>
<blockquote type="cite">   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">
   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&#39;m doing that, but it&#39;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&#39;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&#39;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&#39;s basically this. What i&#39;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&#39;ve been testing, it doesn&#39;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></div></div><div class="im">_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></div></div></blockquote></div><br></div></div><br>_______________________________________________<br>

rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>