There's several things to be noted with the way you've set up these tests.

(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.

(2) I suppose that you ran the tests, one after the other, as one usually
does using Eclipse/JUnit. It's cleaner to do one test in a single run,
preferably not inside Eclipse.

(3) You should be able to control -Xms and -Xmx from the command line, to
see how heap size increments affect execution times.

(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.

Below are the times I've measured using -Xms2048M -Xmx2048M and three DRLs
containing just one rule each.

Test com/rules/PerfTestManual.drl
100000 inserted =     0.245
100000 fired    =     0.282
Test com/rules/PerfTestManual.drl
200000 inserted =     0.434
200000 fired    =     0.546
Test com/rules/PerfTestManual.drl
300000 inserted =     0.607
300000 fired    =     0.863
Test com/rules/PerfTestManual.drl
400000 inserted =     0.828
400000 fired    =     1.557
Test com/rules/PerfTestManual.drl
500000 inserted =     1.017
500000 fired    =     1.838
Test com/rules/PerfTestLogical.drl
100000 inserted =     0.229
100000 fired    =     0.300
Test com/rules/PerfTestLogical.drl
200000 inserted =     0.435
200000 fired    =     0.558
Test com/rules/PerfTestLogical.drl
300000 inserted =     0.560
300000 fired    =     0.716
Test com/rules/PerfTestLogical.drl
400000 inserted =     0.835
400000 fired    =     1.699
Test com/rules/PerfTestLogical.drl
500000 inserted =     0.950
500000 fired    =     1.985
Test com/rules/PerfTestModify.drl
100000 inserted =     0.286
100000 fired    =     0.155
Test com/rules/PerfTestModify.drl
200000 inserted =     0.512
200000 fired    =     0.291
Test com/rules/PerfTestModify.drl
300000 inserted =     0.633
300000 fired    =     0.434
Test com/rules/PerfTestModify.drl
400000 inserted =     0.926
400000 fired    =     0.562
Test com/rules/PerfTestModify.drl
500000 inserted =     1.026
500000 fired    =     0.662

-W

On 10 February 2012 21:43, zstlaw <zstla...@akamai.com> wrote:

> 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
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to