<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Wolfgang –<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks for your response. I have removed the KnowledgeAgent and changed to build the KnowledgeBase without the use of an agent. The ChangeSetXML contains just the compiled binary because there is another process which pulls the compiled binary from the Guvnor. This allows the business users to update the rules in the Guvnor and test in a staging application. When the rules are ready to be moved to production, a process is kicked off that pulls all the binaries from the Guvnor. This allows the business to know exactly when the rules were moved to production and by who [in case there was a problem].<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks again.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] <b>On Behalf Of </b>Wolfgang Laun<br><b>Sent:</b> Thursday, July 14, 2011 5:04 AM<br><b>To:</b> Rules Users List<br><b>Subject:</b> Re: [rules-users] Memory issues<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>Hi,<br><br>it'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'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'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><o:p></o:p></p><div><p class=MsoNormal>2011/7/13 Jeffrey Schneller <<a href="mailto:jeffrey.schneller@envisa.com">jeffrey.schneller@envisa.com</a>><o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>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.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>The Map<X,Y> maps the following:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>X = product name</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>Y = the Knowledge Agent associated to a product.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>Code does the following when rules need to be run against a product.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p><span style='font-size:11.0pt;color:#1F497D'>1)</span><span style='font-size:7.0pt;color:#1F497D'> </span><span style='font-size:11.0pt;color:#1F497D'>Get KnowledgeAgent out of Map based on product name</span><o:p></o:p></p><p><span style='font-size:11.0pt;color:#1F497D'>2)</span><span style='font-size:7.0pt;color:#1F497D'> </span><span style='font-size:11.0pt;color:#1F497D'>Create a StatefulKnowledgeSession</span><o:p></o:p></p><p><span style='font-size:11.0pt;color:#1F497D'>3)</span><span style='font-size:7.0pt;color:#1F497D'> </span><span style='font-size:11.0pt;color:#1F497D'>Insert the facts about the product</span><o:p></o:p></p><p><span style='font-size:11.0pt;color:#1F497D'>4)</span><span style='font-size:7.0pt;color:#1F497D'> </span><span style='font-size:11.0pt;color:#1F497D'>Fire all rules</span><o:p></o:p></p><p><span style='font-size:11.0pt;color:#1F497D'>5)</span><span style='font-size:7.0pt;color:#1F497D'> </span><span style='font-size:11.0pt;color:#1F497D'>Dispose of StatefulKnowledgeSession</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>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.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'>Jeff</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;color:#1F497D'> </span><o:p></o:p></p><div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:-moz-use-text-color -moz-use-text-color'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:10.0pt'> <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</span><o:p></o:p></p></div><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt'>This is strange - do you mean that those 18 KnowledgeAgents stored in that Map produce 18 different StatefulKnowledgeSessions?<br><br>What does the Map<X,Y> map? X? Y?<br><br>-W<o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>2011/7/13 Jeffrey Schneller <<a href="mailto:jeffrey.schneller@envisa.com" target="_blank">jeffrey.schneller@envisa.com</a>><o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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. <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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:<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><?xml version=\"1.0\" encoding=\"UTF-8\"?><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><change-set xmlns='<a href="http://drools.org/drools-5.0/change-set" target="_blank">http://drools.org/drools-5.0/change-set</a>' xmlns:xs='<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>' xs:schemaLocation='<a href="http://drools.org/drools-5.0/change-set.xsd" target="_blank">http://drools.org/drools-5.0/change-set.xsd</a>'><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'><add><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;margin-left:.5in;text-indent:.5in'><resource source='file://PATH_TO_BINARY' type='PKG' /><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'></add><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'></change-set><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>The knowledgeAgentConfiguration is setup as:<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>drools.agent.scanDirectories = false<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>drools.agent.newInstance = false<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>drools.agent.scanResources = false<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>drools.agent.monitorChangeEvents = false<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>After the all the agents are loaded and stored in the hashmap the total memory used in the app is 6.2GB. <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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. <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>The knowledge agent is logging the following when the ruleset is loaded:<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>KnowledgeAgent applying ChangeSet<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>KnowledgeAgent performing an incremental build of the ChangeSet<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:.5in'>KnowledgeAgent incremental build of KnowledgeBase finished and in use<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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?<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Thanks for any help.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt'><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><o:p></o:p></p></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div></div></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><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><o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p></div></body></html>