Execution time for drools5.0 against large data size

4 messages Options
Embed this post
Permalink
ABRA2

Execution time for drools5.0 against large data size

Reply Threaded More More options
Print post
Permalink
Hi

 I would like to test the time taken to run a single rule (eg. HelloWorldExample from Drools5.0 documentation) against large data size (i.e the object inserted in ksession is 10,000). The .drl file is loaded only once and i am looping the part where message object is created and set with values and inserted into ksession for 10,000 times. The time taken was 10.7 secs on an average. Am i doing something wrong? Can i improve it in anyway? Your help is appreciated.
thanks
ABRA

HelloWorld.drl :

package org.drools.examples
 
import org.drools.examples.HelloWorldExample.Message;

global java.util.List list
 
rule "Hello World"
    dialect "mvel"
        when
                m : Message( status == Message.HELLO, message : message)
        then
        System.out.println( message );
        modify ( m ) { message = "Goodbye cruel world",
                       status = Message.GOODBYE };              
end
rule "Good Bye"
    dialect "java"
        when
                Message( status == Message.GOODBYE, message : message )
        then
                System.out.println( message );
end



HelloWorldExample.java
/**
 * This is a sample file to launch a rule package from a rule source file.
 */
public class HelloWorldExample {
       
        public static final void main(final String[] args) throws Exception {
                final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                                .newKnowledgeBuilder();

                // this will parse and compile in one step
                kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
                                HelloWorldExample.class), ResourceType.DRL);

                // Check the builder for errors
                if (kbuilder.hasErrors()) {
                        System.out.println(kbuilder.getErrors().toString());
                        throw new RuntimeException("Unable to compile \"HelloWorld.drl\".");
                }

                // get the compiled packages (which are serializable)
                final Collection<KnowledgePackage> pkgs = kbuilder
                                .getKnowledgePackages();

                // add the packages to a knowledgebase (deploy the knowledge packages).
                final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
                kbase.addKnowledgePackages(pkgs);

                final StatefulKnowledgeSession ksession = kbase
                                .newStatefulKnowledgeSession();
                ksession.setGlobal("list", new ArrayList());

                ksession.addEventListener(new DebugAgendaEventListener());
                ksession.addEventListener(new DebugWorkingMemoryEventListener());

                // setup the audit logging
                KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
                                .newFileLogger(ksession, "log/helloworld");
                long starttime = System.currentTimeMillis();
                for(int u=0;u<10000;u++)
                {
                final Message message = new Message();
                        message.setMessage("Hello World");
                        message.setStatus(Message.HELLO);
                        ksession.insert(message);
                        ksession.fireAllRules();
                }
                 long endtime = System.currentTimeMillis();
                System.out.println("execution time is "+(endtime-starttime));
                logger.close();

                ksession.dispose();
        }

        public static class Message {
                public static final int HELLO = 0;
                public static final int GOODBYE = 1;
                private String message;

                private int status;

                public Message() {

                }

                public String getMessage() {
                        return this.message;
                }

                public void setMessage(final String message) {
                        this.message = message;
                }

                public int getStatus() {
                        return this.status;
                }

                public void setStatus(final int status) {
                        this.status = status;
                }
               
                public static Message doSomething(Message message) {
                        return message;
                }

                public boolean isSomething(String msg, List list) {
                        list.add(this);
                        return this.message.equals(msg);
                }
        }

}

Swindells, Thomas

Re: Execution time for drools5.0 against large data size

Reply Threaded More More options
Print post
Permalink
Have you tried removing the System.out.println statement from the rule? Writing to the console can be very very slow.
You could also get rid of the audit logger which could be spitting out a lot of data into a file (or it may not, I've not actually tried it).

Thomas

> -----Original Message-----
> From: [hidden email] [mailto:rules-users-
> [hidden email]] On Behalf Of ABRA2
> Sent: 04 November 2009 14:15
> To: [hidden email]
> Subject: [rules-users] Execution time for drools5.0 against large data
> size
>
>
> Hi
>
>  I would like to test the time taken to run a single rule (eg.
> HelloWorldExample from Drools5.0 documentation) against large data size
> (i.e
> the object inserted in ksession is 10,000). The .drl file is loaded
> only
> once and i am looping the part where message object is created and set
> with
> values and inserted into ksession for 10,000 times. The time taken was
> 10.7
> secs on an average. Am i doing something wrong? Can i improve it in
> anyway?
> Your help is appreciated.
> thanks
> ABRA
>
> HelloWorld.drl :
>
> package org.drools.examples
>
> import org.drools.examples.HelloWorldExample.Message;
>
> global java.util.List list
>
> rule "Hello World"
>     dialect "mvel"
> when
> m : Message( status == Message.HELLO, message : message)
> then
> System.out.println( message );
> modify ( m ) { message = "Goodbye cruel world",
>               status = Message.GOODBYE };
> end
> rule "Good Bye"
>     dialect "java"
> when
> Message( status == Message.GOODBYE, message : message )
> then
> System.out.println( message );
> end
>
>
>
> HelloWorldExample.java
> /**
>  * This is a sample file to launch a rule package from a rule source
> file.
>  */
> public class HelloWorldExample {
>
> public static final void main(final String[] args) throws
> Exception {
> final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
> .newKnowledgeBuilder();
>
> // this will parse and compile in one step
>
> kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl
> ",
> HelloWorldExample.class), ResourceType.DRL);
>
> // Check the builder for errors
> if (kbuilder.hasErrors()) {
> System.out.println(kbuilder.getErrors().toString());
> throw new RuntimeException("Unable to compile
> \"HelloWorld.drl\".");
> }
>
> // get the compiled packages (which are serializable)
> final Collection<KnowledgePackage> pkgs = kbuilder
> .getKnowledgePackages();
>
> // add the packages to a knowledgebase (deploy the
> knowledge packages).
> final KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase();
> kbase.addKnowledgePackages(pkgs);
>
> final StatefulKnowledgeSession ksession = kbase
> .newStatefulKnowledgeSession();
> ksession.setGlobal("list", new ArrayList());
>
> ksession.addEventListener(new DebugAgendaEventListener());
> ksession.addEventListener(new
> DebugWorkingMemoryEventListener());
>
> // setup the audit logging
> KnowledgeRuntimeLogger logger =
> KnowledgeRuntimeLoggerFactory
> .newFileLogger(ksession, "log/helloworld");
> long starttime = System.currentTimeMillis();
> for(int u=0;u<10000;u++)
> {
> final Message message = new Message();
> message.setMessage("Hello World");
> message.setStatus(Message.HELLO);
> ksession.insert(message);
> ksession.fireAllRules();
> }
> long endtime = System.currentTimeMillis();
>        System.out.println("execution time is "+(endtime-
> starttime));
> logger.close();
>
> ksession.dispose();
> }
>
> public static class Message {
> public static final int HELLO = 0;
> public static final int GOODBYE = 1;
> private String message;
>
> private int status;
>
> public Message() {
>
> }
>
> public String getMessage() {
> return this.message;
> }
>
> public void setMessage(final String message) {
> this.message = message;
> }
>
> public int getStatus() {
> return this.status;
> }
>
> public void setStatus(final int status) {
> this.status = status;
> }
>
> public static Message doSomething(Message message) {
> return message;
> }
>
> public boolean isSomething(String msg, List list) {
> list.add(this);
> return this.message.equals(msg);
> }
> }
>
> }
>
>
> --
> View this message in context: http://old.nabble.com/Execution-time-for-
> drools5.0-against-large-data-size-tp26195944p26195944.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the [hidden email] and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Jared Davis

Re: Execution time for drools5.0 against large data size

Reply Threaded More More options
Print post
Permalink
What happens if you move line "ksession.fireAllRules();" to after the loop?



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
ABRA2

Re: Execution time for drools5.0 against large data size

Reply Threaded More More options
Print post
Permalink
I have tried couple of things as suggested by the rules user list. It has improved the execution time of hello world example to some extent.

1. Moving fireallRules() out of the loop - helped very little, execution time was almost same(150 millisecs less). - 10.35 secs
2. Commenting out the audit logger used in the example - cut the execution time by half  5.67 secs
3. Removing system.outs from rules - reduces 2 secs of execution time - 3.433

The final execution time for HelloWorldExample in drools5.0 is 3.4 secs and in Java is  256 milli secs. (I am attaching the java version of drools example also to this email) .

package org.drools.examples;

import java.util.List;

import org.drools.examples.HelloWorldExample.Message;

public class HelloWorldJavaExample {
        public static long starttime = 0;
         public static long endtime =0;
        public static void hello(Message message)
        {
                System.out.println(message.getMessage());
                message.setMessage("Good Bye Cruel World");
                message.setStatus(Message.GOODBYE);
                goodbye(message);
        }
        public static void goodbye(Message message)
        {
                System.out.println(message.getMessage());
               
        }
        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                starttime = System.currentTimeMillis();
                for(int u=0;u<10000;u++)
                {
                        final Message message = new Message();
                        message.setMessage("Hello World");
                        message.setStatus(Message.HELLO);
                        if(message.getMessage().equalsIgnoreCase("Hello World"))
                        {
                                hello(message);
                        }
                }
               
                 endtime = System.currentTimeMillis();
             System.out.println("execution time in main is "+(endtime-starttime));
        }
        public static class Message {
                public static final int HELLO = 0;
                public static final int GOODBYE = 1;
                private String message;

                private int status;

                public Message() {

                }

                public String getMessage() {
                        return this.message;
                }

                public void setMessage(final String message) {
                        this.message = message;
                }

                public int getStatus() {
                        return this.status;
                }

                public void setStatus(final int status) {
                        this.status = status;
                }
               
                public static Message doSomething(Message message) {
                        return message;
                }

                public boolean isSomething(String msg, List list) {
                        list.add(this);
                        return this.message.equals(msg);
                }
        }

}

thanks for your suggestions.
ABRA2