<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: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)">
<title>Scaling to large numbers of rules</title>
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
 /* 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";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</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=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Adam,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>There are several ways to deal with large number of rules.&nbsp;
For example, instead of re-compiling the whole rule set every time, you could
just compile the rules that are updated/new, then adding them to the existing
KnowledgeBase instance.&nbsp; Drools is capable to handle such usage, even
during rule execution &#8211; but would not recommend to do that.&nbsp; API&#8217;s
are also available to remove packages, rules, etc.&nbsp; &nbsp;We are using something
similar for generated rules.&nbsp; <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>It is also important to note that it would require persisting
the KnowledgeBase so it could be reloaded after restarting the application.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Just a thought.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>-Ming<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<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>Adam Sussman<br>
<b>Sent:</b> Wednesday, September 02, 2009 7:21 PM<br>
<b>To:</b> rules-users@lists.jboss.org<br>
<b>Subject:</b> [rules-users] Scaling to large numbers of rules<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p><span style='font-size:10.0pt'>I am hoping that I am doing something wrong
here and that one of you can<br>
point me in the right direction.<br>
<br>
Can anyone provide some advice on scaling up the number of rules in a<br>
single KnowledgeBase?&nbsp; While I have seen all sorts of reports on having<br>
lots of facts, I have not seen anything about having lots of rules.<br>
<br>
I need to get to about 200K rules in a single KnowledgeBase, and also<br>
to run several of these side by side in the same system.<br>
<br>
The problem:<br>
<br>
As the number of rules increases, the time to compile and load them<br>
into memory skyrockets.&nbsp; Now while I realize that the Rete algorithm<br>
complexity is about the number of rules, the times I am seeing are<br>
pretty scary.&nbsp; Also, at about 30k rules, things just fall apart.<br>
<br>
On a 64 bit Linux OS with 2 2.4Ghz processors using a 64bit JVM from<br>
OpenJDK (1.6.1) with 1 Gig of memory allocated to the JVM, loading<br>
from .drl files:<br>
<br>
1000 rules:<br>
&nbsp;&nbsp;&nbsp;
KnowledgeBuilder.add:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
7 seconds<br>
&nbsp;&nbsp;&nbsp; KnowledgeBase.addKnowledgePackages:&nbsp;&nbsp;&nbsp;&nbsp;
.8 seconds<br>
<br>
10000 rules:<br>
&nbsp;&nbsp;&nbsp;
KnowledgeBuilder.add:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
79 seconds<br>
&nbsp;&nbsp;&nbsp; KnowledgeBase.addKnowledgePackages:&nbsp;&nbsp;&nbsp;&nbsp;
23 seconds<br>
<br>
15000 rules:<br>
&nbsp;&nbsp;&nbsp;
KnowledgeBuilder.add:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
138 seconds<br>
&nbsp;&nbsp;&nbsp;
KnowledgeBase.addKnowledgePackages:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 55 seconds<br>
<br>
20000 rules:<br>
&nbsp;&nbsp;&nbsp; KnowledgeBuilder.add:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
488 seconds<br>
&nbsp;&nbsp;&nbsp; KnowledgeBase.addKnowledgePackages:&nbsp;&nbsp;&nbsp;&nbsp;
100 seconds<br>
<br>
30000 rules:<br>
&nbsp;&nbsp;&nbsp;
KnowledgeBuilder.add:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
out of memory<br>
&nbsp;&nbsp;&nbsp; KnowledgeBase.addKnowledgePackages:&nbsp;&nbsp;&nbsp;&nbsp;
never runs<br>
<br>
At this rate, 200k rules will take 13-14 hours to compile<br>
and 2-3 hours to load into RAM, assuming I can even get<br>
to that many rules.&nbsp; This just is not usable.<br>
<br>
Time to fire all rules is negligible (fortunately!).<br>
<br>
The rules I am testing on are very simple 1-3 variable equality whens<br>
with a simple System.out.println then clause.<br>
<br>
The benchmark code I am running is as follows:<br>
<br>
&nbsp;&nbsp;&nbsp; KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();<br>
&nbsp;&nbsp;&nbsp; KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
<br>
&nbsp;&nbsp;&nbsp; kbuilder.add( ResourceFactory.newClassPathResource( drlFile,
RuleRunner.class ), ResourceType.DRL );<br>
<br>
&nbsp;&nbsp;&nbsp; Collection&lt;KnowledgePackage&gt; pkgs =
kbuilder.getKnowledgePackages();<br>
&nbsp;&nbsp;&nbsp; kbase.addKnowledgePackages( pkgs );<br>
<br>
<br>
Sample rule:<br>
<br>
&nbsp;&nbsp;&nbsp; rule &quot;00000005 - random rule&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Transaction(someId == 35156 &amp;&amp; someOtherId == '79F81FB8134A129F'
&amp;&amp; someCollection contains 'EC3F2A1DCA88')<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(&quot;match rule 00000005 - random rule&quot;);<br>
&nbsp;&nbsp;&nbsp; end<br>
<br>
Any help would be appreciated.<br>
<br>
Regards,<br>
<br>
Adam Sussman</span><o:p></o:p></p>

<pre>CONFIDENTIALITY NOTICE:<o:p></o:p></pre><pre><o:p>&nbsp;</o:p></pre><pre>This message contains information which may be confidential or privileged.&nbsp; If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited.&nbsp; If you have received this transmission in error, please notify me immediately by telephone.<o:p></o:p></pre></div>

</body>

</html>