[rules-users] Execution time for drools5.0 against large data size

Swindells, Thomas TSwindells at nds.com
Wed Nov 4 09:26:01 EST 2009


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: rules-users-bounces at lists.jboss.org [mailto:rules-users-
> bounces at lists.jboss.org] On Behalf Of ABRA2
> Sent: 04 November 2009 14:15
> To: rules-users at lists.jboss.org
> 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
> rules-users at lists.jboss.org
> 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 postmaster at nds.com 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
**************************************************************************************




More information about the rules-users mailing list