[rules-users] Performance issue

Ini inder.14 at gmail.com
Thu May 31 02:25:53 EDT 2012


Hi All,
		I have written a code to check the properties of a bean using drools based
rules.
		I have created the different rules file where different properties of the
bean will be checked.
		
		The code i have written is a as below:

public static void check(Object details,String rule){
		
		long methodStartTime=System.currentTimeMillis();
		Resource resource = new ClassPathResource(RULE_CLASSPATH+rule);  
		
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		long startTime=System.currentTimeMillis();
		kbuilder.add(resource, ResourceType.DRL );
		long endTime=System.currentTimeMillis();
		System.out.println("Time taken in add resource in milli seconds
is::"+(endTime-startTime));
		 KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
			kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
			 KnowledgeBuilderErrors errors = kbuilder.getErrors();
			 if (errors.size() > 0) {
				 for (KnowledgeBuilderError error: errors) {
					 System.err.println(error);
				 }
			 }
			 
			 StatelessKnowledgeSession  ksession =
kbase.newStatelessKnowledgeSession();
			 			
			 
			 ksession.execute(details);
			 long methodEndTime=System.currentTimeMillis();
			 
			 System.out.println("Time taken in Method check  in milli seconds
is::"+(methodEndTime-methodStartTime));
			 
	}
	
	Here in the check method we have three parameters details this is the bean
whose properties need to be checked in rules file, rule this is the name of
rules file which contains all the rules.
	
	Here the issue is that it takes around 4 seconds for the first time and 1
second for all consecutive requests, and 4 second looks too much time for
validating the rules file that has only 10 rules.
	
	Please let me know we have some better way of doing it in drools

--
View this message in context: http://drools.46999.n3.nabble.com/Performance-issue-tp4017688.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list