The first optimization I can advice (without knowing your rules) is to keep the kbase cached instead of being compiling the resources and creating it for each request.<div>You can compile the resources with kbuilder once, create a kbase once and then for each request you only need to create a ksession from the already existing kbase and use it.</div>
<div>The compilation of the rules is (usually) one of the most time-consuming tasks you have in drools.</div><div><br></div><div>Best Regards, <br clear="all"><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com </a><br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
<br><br><div class="gmail_quote">On Thu, May 31, 2012 at 8:25 AM, Ini <span dir="ltr"><<a href="mailto:inder.14@gmail.com" target="_blank">inder.14@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
I have written a code to check the properties of a bean using drools based<br>
rules.<br>
I have created the different rules file where different properties of the<br>
bean will be checked.<br>
<br>
The code i have written is a as below:<br>
<br>
public static void check(Object details,String rule){<br>
<br>
long methodStartTime=System.currentTimeMillis();<br>
Resource resource = new ClassPathResource(RULE_CLASSPATH+rule);<br>
<br>
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
long startTime=System.currentTimeMillis();<br>
kbuilder.add(resource, ResourceType.DRL );<br>
long endTime=System.currentTimeMillis();<br>
System.out.println("Time taken in add resource in milli seconds<br>
is::"+(endTime-startTime));<br>
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );<br>
KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
if (errors.size() > 0) {<br>
for (KnowledgeBuilderError error: errors) {<br>
System.err.println(error);<br>
}<br>
}<br>
<br>
StatelessKnowledgeSession ksession =<br>
kbase.newStatelessKnowledgeSession();<br>
<br>
<br>
ksession.execute(details);<br>
long methodEndTime=System.currentTimeMillis();<br>
<br>
System.out.println("Time taken in Method check in milli seconds<br>
is::"+(methodEndTime-methodStartTime));<br>
<br>
}<br>
<br>
Here in the check method we have three parameters details this is the bean<br>
whose properties need to be checked in rules file, rule this is the name of<br>
rules file which contains all the rules.<br>
<br>
Here the issue is that it takes around 4 seconds for the first time and 1<br>
second for all consecutive requests, and 4 second looks too much time for<br>
validating the rules file that has only 10 rules.<br>
<br>
Please let me know we have some better way of doing it in drools<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Performance-issue-tp4017688.html" target="_blank">http://drools.46999.n3.nabble.com/Performance-issue-tp4017688.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br></div>