I just made a simple self contained example to demonstrate the problem
better.  It entirely depends on the two included files. This was run on
5.3.1.Final.

Results of test runs :
   Setup with 10000 in 2524
   LogicalInsertPerformance with 10000 in 17049
   ManualInsertPerformance with 10000 in 17841
   ModifyPerformance with 10000 in 9679
   Setup with 20000 in 13156
   LogicalInsertPerformance with 20000 in 84740
   ManualInsertPerformance with 20000 in 100079
   ModifyPerformance with 20000 in 25267

You can see how doubling the number of objects increases time by a factor of
4 in all but the modify example.

//
----------------------------------------------------------------------------------------
// START RULE FILE PerfTestRules.drl
//
----------------------------------------------------------------------------------------
package com.rules;
dialect "java"
 
declare SimpleDataPoint
        value : int
        id : int
        alert : boolean    // for modify and manualInsert tests
        alertRule : String // for modify test only
end

declare SimpleAlert
        datapoint : SimpleDataPoint
        ruleName : String
end

rule "SetUp"
    when
        $amtData : Integer()
    then
        for (int x=0; x< $amtData.intValue(); x++) {
           insert(new SimpleDataPoint(11, x, false, null));
        }
end


rule "LogicalInsertPerformance"
    when
                $datapoint : SimpleDataPoint (
                        value > 0
                )
    then
        insertLogical(new SimpleAlert($datapoint, drools.getRule().getName()));
end

rule "ManualInsertPerformance"
        no-loop
    when
                $datapoint : SimpleDataPoint (
                        value > 0,
                        !alert
                )
    then
        insert(new SimpleAlert($datapoint, drools.getRule().getName()));
        modify($datapoint) {setAlert(true)};
end

rule "ModifyPerformance"
        no-loop
    when
                $datapoint : SimpleDataPoint (
                        value > 0,
                        !alert
                )
    then
        modify($datapoint) {setAlert(true),
setAlertRule(drools.getRule().getName())};
end

//
----------------------------------------------------------------------------------------
// JUNIT file SimplePerfTest.java used to setup and run tests.
//
----------------------------------------------------------------------------------------
package com.rules;

import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.conf.AssertBehaviorOption;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.rule.Activation;
import org.drools.runtime.rule.AgendaFilter;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SimplePerfTest {

        private StatefulKnowledgeSession rulesSession = null;
        java.util.ArrayList<String> allowList = new 
java.util.ArrayList<String>();

        @Before
        public void setUp() {
                // this will parse and compile in one step
                final KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
                kbuilder.add( 
ResourceFactory.newClassPathResource("PerfTestRules.drl",
SimplePerfTest.class ),
                                ResourceType.DRL );
                if ( kbuilder.hasErrors() ) {
                        throw new IllegalStateException( 
kbuilder.getErrors().toString() );
                }

                allowList.add("SetUp");

                // do not allow identical objects to be asserted separately
                KnowledgeBaseConfiguration kbConf =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
                kbConf.setOption(AssertBehaviorOption.EQUALITY);
                KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(kbConf);
                
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
                rulesSession = knowledgeBase.newStatefulKnowledgeSession();
        }

        /** clean up test environment 
         * @throws RuleManagerException */
        @After
        public void tearDown() {
                allowList.clear();
                if (rulesSession!=null) {
                        rulesSession.dispose();
                }
                rulesSession = null;
        }

        @Test public void testSetup10k() {
                testPerf(10000);                
        }

        @Test public void testLogicalInsert10k() {
                allowList.add("LogicalInsertPerformance");
                testPerf(10000);                
        }

        @Test public void testManualInsert10k() {
                allowList.add("ManualInsertPerformance");
                testPerf(10000);                
        }

        @Test public void testModify10k() {
                allowList.add("ModifyPerformance");
                testPerf(10000);                
        }

        @Test public void testSetup20k() {
                testPerf(20000);                
        }

        @Test public void testLogicalInsert20k() {
                allowList.add("LogicalInsertPerformance");
                testPerf(20000);                
        }

        @Test public void testManualInsert20k() {
                allowList.add("ManualInsertPerformance");
                testPerf(20000);                
        }

        @Test public void testModify20k() {
                allowList.add("ModifyPerformance");
                testPerf(20000);                
        }

        private void testPerf(final Integer AMT_DATA) {
                rulesSession.insert(AMT_DATA);
                long start = System.currentTimeMillis();
                rulesSession.fireAllRules(new AgendaFilter() {
                        @Override
                        public boolean accept(Activation activation) {
                                return 
allowList.contains(activation.getRule().getName());
                        }
                });
                System.out.println(allowList.get(allowList.size()-1) +" with 
"+AMT_DATA+"
in " + (System.currentTimeMillis()-start));
        }
}




--
View this message in context: 
http://drools.46999.n3.nabble.com/rules-users-Performance-scaling-with-fact-insertion-tp3727727p3733629.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to