Hi,<br><br>it&#39;s still guesswork in parts - circumstantial evidence at best.<br><br>The purpose of a KnowledgeAgent is to monitor resources for building a KnowledgeBase, typically by periodic inspection of certain parts of the file system and reacting to updates. But you set all scan.X properties to false, turning the feature completely off.<br>
<br>This means that you use a KnowledgeAgent merely as a convenience tool for creating a rule base. This is a sign of laziness (one of the <a href="http://c2.com/cgi/wiki?LazinessImpatienceHubris">three great virtues of a programmer</a>) but even it must be exercised with care.  However: why does the change Set XML contain just the compiled binary? This means that stuff is compiled elsewhere, and only the result copied to a place that&#39;s being monitored by - which part of your application?<br>
<br>Agents are notoriously hard to kill, and the KA is one of these. If, for instance you start resource change monitoring for an agent, it&#39;ll run a thread that keeps a reference to the KA. So, just wiping a Map will not rid the program of the KA objects, and this is bound to keep a lot of other biggies alive.<br>
<br>Did you ever monitor to see running threads? Or existing objects per class?<br><br>HTH<br>-W<br><br><br><br><div class="gmail_quote">2011/7/13 Jeffrey Schneller <span dir="ltr">&lt;<a href="mailto:jeffrey.schneller@envisa.com">jeffrey.schneller@envisa.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 link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Yes.  The 18 KnowledgeAgents produce 18 StatefulKnowledgeSessions when they are needed.  The session has dispose() called on it when it is not needed any longer.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">The Map&lt;X,Y&gt; maps the following:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">X = product name<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Y = the Knowledge Agent associated to a product.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Code does the following when rules need to be run against a product.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>1)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span></span><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);">Get KnowledgeAgent out of Map based on product name<u></u><u></u></span></p>
<p><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>2)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span></span><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);">Create a StatefulKnowledgeSession<u></u><u></u></span></p>
<p><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>3)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span></span><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);">Insert the facts about the product<u></u><u></u></span></p>
<p><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>4)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span></span><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);">Fire all rules<u></u><u></u></span></p>
<p><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>5)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">      </span></span></span><u></u><span style="font-size: 11pt; color: rgb(31, 73, 125);">Dispose of StatefulKnowledgeSession<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">We have no problems with the 5 steps that are followed.  The rules are configuration and pricing rules for each product.  The facts are the options specified for a particular product. The rules compute the price of the product as specified by the desired options and any incompatible options selected [very similar to what you would see on car manufacturers website for pricing a particular car]  If there is a better way to do this, I would be interested in knowing.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Jeff<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><u></u> <u></u></span></p><div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">
<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>Wolfgang Laun<br>
<b>Sent:</b> Wednesday, July 13, 2011 1:27 PM<br><b>To:</b> Rules Users List<br><b>Subject:</b> Re: [rules-users] Memory issues<u></u><u></u></span></p></div><div><div></div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-bottom: 12pt;">This is strange - do you mean that those 18 KnowledgeAgents stored in that Map produce 18 different StatefulKnowledgeSessions?<br><br>What does the Map&lt;X,Y&gt; map? X? Y?<br>
<br>-W<u></u><u></u></p><div><p class="MsoNormal">2011/7/13 Jeffrey Schneller &lt;<a href="mailto:jeffrey.schneller@envisa.com" target="_blank">jeffrey.schneller@envisa.com</a>&gt;<u></u><u></u></p><div><div><p class="MsoNormal">
I am currently running version 5.1.0M2.  I have 18 different binary rulesets [packages] that are stored on the local filesystem.  The rulesets range in size from 4K to 131Mb. <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">When my application starts I load each ruleset into a knowledgeAgent and store the knowledgeAgent into a hashmap which is stored in memory.   They are loaded using the following xml:<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;<u></u><u></u></p><p class="MsoNormal">&lt;change-set xmlns=&#39;<a href="http://drools.org/drools-5.0/change-set" target="_blank">http://drools.org/drools-5.0/change-set</a>&#39; xmlns:xs=&#39;<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>&#39; xs:schemaLocation=&#39;<a href="http://drools.org/drools-5.0/change-set.xsd" target="_blank">http://drools.org/drools-5.0/change-set.xsd</a>&#39;&gt;<u></u><u></u></p>
<p class="MsoNormal" style="text-indent: 0.5in;">&lt;add&gt;<u></u><u></u></p><p class="MsoNormal" style="margin-left: 0.5in; text-indent: 0.5in;">&lt;resource source=&#39;file://PATH_TO_BINARY&#39; type=&#39;PKG&#39; /&gt;<u></u><u></u></p>
<p class="MsoNormal" style="text-indent: 0.5in;">&lt;/add&gt;<u></u><u></u></p><p class="MsoNormal">&lt;/change-set&gt;<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">The knowledgeAgentConfiguration is setup as:<u></u><u></u></p>
<p class="MsoNormal" style="text-indent: 0.5in;">drools.agent.scanDirectories = false<u></u><u></u></p><p class="MsoNormal" style="text-indent: 0.5in;">drools.agent.newInstance = false<u></u><u></u></p><p class="MsoNormal" style="text-indent: 0.5in;">
drools.agent.scanResources = false<u></u><u></u></p><p class="MsoNormal" style="text-indent: 0.5in;">drools.agent.monitorChangeEvents = false<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">After the all the agents are loaded and stored in the hashmap the total memory used in the app is 6.2GB.  <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Once the application is running, if a business user needs to update a set of rules there is a process in place to refresh all the knowledgeAgents with new rulesets.  In a new thread. the code clears the hashmap, sets the hashmap to null, calls for garbage collection to occur, and it then constructs a new hashmap and loads all the rules as it does at application startup. <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">The knowledge agent is logging the following when the ruleset is loaded:<u></u><u></u></p><p class="MsoNormal" style="text-indent: 0.5in;">KnowledgeAgent applying ChangeSet<u></u><u></u></p>
<p class="MsoNormal" style="text-indent: 0.5in;">KnowledgeAgent performing an incremental build of the ChangeSet<u></u><u></u></p><p class="MsoNormal" style="text-indent: 0.5in;">KnowledgeAgent incremental build of KnowledgeBase finished and in use<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">It takes a large amount of time to do this process [double to triple the time of application startup]. After this occurs the memory used by the app increases [to nearly double the original size 12.2GB] and the CPU is maxed out.  After some time the CPU usage drops and the app is usable again but the memory never decreases.  If a business user refreshes the rules again, the memory increases again and the CPU is maxed out and the app becomes unresponsive because the memory is completely maxed out.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">There is obviously a memory leak somewhere and a large one at that.  Is this the proper way to be caching KnowledgeAgents into memory so the rulessets don’t need to be re-loaded everytime a knowledgeAgent is run?  Is my problem the use of the hashmap?  Do I need to remove the original knowledgeAgents that were in the hashmap?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks for any help.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p></div></div><p class="MsoNormal" style="margin-bottom: 12pt;">
<br>_______________________________________________<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><u></u><u></u></p>
</div><p class="MsoNormal"><u></u> <u></u></p></div></div></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>