[rules-users] Performance issue
Esteban Aliverti
esteban.aliverti at gmail.com
Thu May 31 03:08:09 EDT 2012
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.
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.
The compilation of the rules is (usually) one of the most time-consuming
tasks you have in drools.
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com
On Thu, May 31, 2012 at 8:25 AM, Ini <inder.14 at gmail.com> wrote:
> 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.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120531/9911dff8/attachment.html
More information about the rules-users
mailing list