There&#39;s several things to be noted with the way you&#39;ve set up these tests.<div><br></div><div>(1) You run all tests (Logical, Manual, Modify) with all three rules being in the KnowledgeBase. This means that all insertions result in the creation of activations for all three rules while firings are restricted using the agenda filter.</div>
<div><br></div><div>(2) I suppose that you ran the tests, one after the other, as one usually does using Eclipse/JUnit. It&#39;s cleaner to do one test in a single run, preferably not inside Eclipse.</div><div><br></div><div>
(3) You should be able to control -Xms and -Xmx from the command line, to see how heap size increments affect execution times.</div><div><br></div><div>(4) Insert facts from Java: This lets you distinguish between the time required for inserting (i.e., evaluating the conditions and creatign the agenda) and firing.</div>
<div> </div><div>Below are the times I&#39;ve measured using -Xms2048M -Xmx2048M and three DRLs containing just one rule each. </div><div><br></div><div><div>Test com/rules/PerfTestManual.drl</div><div>100000 inserted =     0.245</div>
<div>100000 fired    =     0.282</div><div>Test com/rules/PerfTestManual.drl</div><div>200000 inserted =     0.434</div><div>200000 fired    =     0.546</div><div>Test com/rules/PerfTestManual.drl</div><div>300000 inserted =     0.607</div>
<div>300000 fired    =     0.863</div><div>Test com/rules/PerfTestManual.drl</div><div>400000 inserted =     0.828</div><div>400000 fired    =     1.557</div><div>Test com/rules/PerfTestManual.drl</div><div>500000 inserted =     1.017</div>
<div>500000 fired    =     1.838</div><div>Test com/rules/PerfTestLogical.drl</div><div>100000 inserted =     0.229</div><div>100000 fired    =     0.300</div><div>Test com/rules/PerfTestLogical.drl</div><div>200000 inserted =     0.435</div>
<div>200000 fired    =     0.558</div><div>Test com/rules/PerfTestLogical.drl</div><div>300000 inserted =     0.560</div><div>300000 fired    =     0.716</div><div>Test com/rules/PerfTestLogical.drl</div><div>400000 inserted =     0.835</div>
<div>400000 fired    =     1.699</div><div>Test com/rules/PerfTestLogical.drl</div><div>500000 inserted =     0.950</div><div>500000 fired    =     1.985</div><div>Test com/rules/PerfTestModify.drl</div><div>100000 inserted =     0.286</div>
<div>100000 fired    =     0.155</div><div>Test com/rules/PerfTestModify.drl</div><div>200000 inserted =     0.512</div><div>200000 fired    =     0.291</div><div>Test com/rules/PerfTestModify.drl</div><div>300000 inserted =     0.633</div>
<div>300000 fired    =     0.434</div><div>Test com/rules/PerfTestModify.drl</div><div>400000 inserted =     0.926</div><div>400000 fired    =     0.562</div><div>Test com/rules/PerfTestModify.drl</div><div>500000 inserted =     1.026</div>
<div>500000 fired    =     0.662</div></div><div><br></div><div>-W</div><div><div><br><div class="gmail_quote">On 10 February 2012 21:43, zstlaw <span dir="ltr">&lt;<a href="mailto:zstlawre@akamai.com">zstlawre@akamai.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I just made a simple self contained example to demonstrate the problem<br>
better.  It entirely depends on the two included files. This was run on<br>
5.3.1.Final.<br>
<br>
Results of test runs :<br>
   Setup with 10000 in 2524<br>
   LogicalInsertPerformance with 10000 in 17049<br>
   ManualInsertPerformance with 10000 in 17841<br>
   ModifyPerformance with 10000 in 9679<br>
   Setup with 20000 in 13156<br>
   LogicalInsertPerformance with 20000 in 84740<br>
   ManualInsertPerformance with 20000 in 100079<br>
   ModifyPerformance with 20000 in 25267<br>
<br>
You can see how doubling the number of objects increases time by a factor of<br>
4 in all but the modify example.<br>
<br>
//<br>
----------------------------------------------------------------------------------------<br>
// START RULE FILE PerfTestRules.drl<br>
//<br>
----------------------------------------------------------------------------------------<br>
package com.rules;<br>
dialect &quot;java&quot;<br>
<br>
declare SimpleDataPoint<br>
        value : int<br>
        id : int<br>
        alert : boolean    // for modify and manualInsert tests<br>
        alertRule : String // for modify test only<br>
end<br>
<br>
declare SimpleAlert<br>
        datapoint : SimpleDataPoint<br>
        ruleName : String<br>
end<br>
<br>
rule &quot;SetUp&quot;<br>
    when<br>
        $amtData : Integer()<br>
    then<br>
        for (int x=0; x&lt; $amtData.intValue(); x++) {<br>
           insert(new SimpleDataPoint(11, x, false, null));<br>
        }<br>
end<br>
<br>
<br>
rule &quot;LogicalInsertPerformance&quot;<br>
    when<br>
                $datapoint : SimpleDataPoint (<br>
                        value &gt; 0<br>
                )<br>
    then<br>
        insertLogical(new SimpleAlert($datapoint, drools.getRule().getName()));<br>
end<br>
<br>
rule &quot;ManualInsertPerformance&quot;<br>
        no-loop<br>
    when<br>
                $datapoint : SimpleDataPoint (<br>
                        value &gt; 0,<br>
                        !alert<br>
                )<br>
    then<br>
        insert(new SimpleAlert($datapoint, drools.getRule().getName()));<br>
        modify($datapoint) {setAlert(true)};<br>
end<br>
<br>
rule &quot;ModifyPerformance&quot;<br>
        no-loop<br>
    when<br>
                $datapoint : SimpleDataPoint (<br>
                        value &gt; 0,<br>
                        !alert<br>
                )<br>
    then<br>
        modify($datapoint) {setAlert(true),<br>
setAlertRule(drools.getRule().getName())};<br>
end<br>
<br>
//<br>
----------------------------------------------------------------------------------------<br>
// JUNIT file SimplePerfTest.java used to setup and run tests.<br>
//<br>
----------------------------------------------------------------------------------------<br>
package com.rules;<br>
<br>
import org.drools.KnowledgeBase;<br>
import org.drools.KnowledgeBaseConfiguration;<br>
import org.drools.KnowledgeBaseFactory;<br>
import org.drools.builder.KnowledgeBuilder;<br>
import org.drools.builder.KnowledgeBuilderFactory;<br>
import org.drools.builder.ResourceType;<br>
import org.drools.conf.AssertBehaviorOption;<br>
import org.drools.io.ResourceFactory;<br>
import org.drools.runtime.StatefulKnowledgeSession;<br>
import org.drools.runtime.rule.Activation;<br>
import org.drools.runtime.rule.AgendaFilter;<br>
<br>
import org.junit.After;<br>
import org.junit.Before;<br>
import org.junit.Test;<br>
<br>
public class SimplePerfTest {<br>
<br>
        private StatefulKnowledgeSession rulesSession = null;<br>
        java.util.ArrayList&lt;String&gt; allowList = new java.util.ArrayList&lt;String&gt;();<br>
<br>
        @Before<br>
        public void setUp() {<br>
                // this will parse and compile in one step<br>
                final KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
                kbuilder.add( ResourceFactory.newClassPathResource(&quot;PerfTestRules.drl&quot;,<br>
SimplePerfTest.class ),<br>
                                ResourceType.DRL );<br>
                if ( kbuilder.hasErrors() ) {<br>
                        throw new IllegalStateException( kbuilder.getErrors().toString() );<br>
                }<br>
<br>
                allowList.add(&quot;SetUp&quot;);<br>
<br>
                // do not allow identical objects to be asserted separately<br>
                KnowledgeBaseConfiguration kbConf =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
                kbConf.setOption(AssertBehaviorOption.EQUALITY);<br>
                KnowledgeBase knowledgeBase =<br>
KnowledgeBaseFactory.newKnowledgeBase(kbConf);<br>
                knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
                rulesSession = knowledgeBase.newStatefulKnowledgeSession();<br>
        }<br>
<br>
        /** clean up test environment<br>
         * @throws RuleManagerException */<br>
        @After<br>
        public void tearDown() {<br>
                allowList.clear();<br>
                if (rulesSession!=null) {<br>
                        rulesSession.dispose();<br>
                }<br>
                rulesSession = null;<br>
        }<br>
<br>
        @Test public void testSetup10k() {<br>
                testPerf(10000);<br>
        }<br>
<br>
        @Test public void testLogicalInsert10k() {<br>
                allowList.add(&quot;LogicalInsertPerformance&quot;);<br>
                testPerf(10000);<br>
        }<br>
<br>
        @Test public void testManualInsert10k() {<br>
                allowList.add(&quot;ManualInsertPerformance&quot;);<br>
                testPerf(10000);<br>
        }<br>
<br>
        @Test public void testModify10k() {<br>
                allowList.add(&quot;ModifyPerformance&quot;);<br>
                testPerf(10000);<br>
        }<br>
<br>
        @Test public void testSetup20k() {<br>
                testPerf(20000);<br>
        }<br>
<br>
        @Test public void testLogicalInsert20k() {<br>
                allowList.add(&quot;LogicalInsertPerformance&quot;);<br>
                testPerf(20000);<br>
        }<br>
<br>
        @Test public void testManualInsert20k() {<br>
                allowList.add(&quot;ManualInsertPerformance&quot;);<br>
                testPerf(20000);<br>
        }<br>
<br>
        @Test public void testModify20k() {<br>
                allowList.add(&quot;ModifyPerformance&quot;);<br>
                testPerf(20000);<br>
        }<br>
<br>
        private void testPerf(final Integer AMT_DATA) {<br>
                rulesSession.insert(AMT_DATA);<br>
                long start = System.currentTimeMillis();<br>
                rulesSession.fireAllRules(new AgendaFilter() {<br>
                        @Override<br>
                        public boolean accept(Activation activation) {<br>
                                return allowList.contains(activation.getRule().getName());<br>
                        }<br>
                });<br>
                System.out.println(allowList.get(allowList.size()-1) +&quot; with &quot;+AMT_DATA+&quot;<br>
in &quot; + (System.currentTimeMillis()-start));<br>
        }<br>
}<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/rules-users-Performance-scaling-with-fact-insertion-tp3727727p3733629.html" target="_blank">http://drools.46999.n3.nabble.com/rules-users-Performance-scaling-with-fact-insertion-tp3727727p3733629.html</a><br>

<div class="HOEnZb"><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<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>
</div></div></blockquote></div><br></div></div>