[rules-users] Is there a faster way of doing this in Drools ?

Mauricio Salatino salaboy at gmail.com
Wed May 9 07:58:27 EDT 2012


You can do that step once and then reload the compiled rules from the disk,
or use guvnor which will compile the rules for you.
Cheers

On Wed, May 9, 2012 at 12:55 PM, soumya_sd <soumya_sd at yahoo.com> wrote:

> I've a use case where I need to create a rule dynamically every time the
> user
> sends a request.
> My current understanding of Drools is that you need to create a
> KnowledgeBuilder and then add the rules
>
> I'm creating the KnowledgeBase as follows.
>
>    private static KnowledgeBase readKnowledgeBase() throws Exception {
>        long t1 = System.currentTimeMillis();
>        KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>        long t11 = System.currentTimeMillis();
>
>
>        kbuilder.add(
> org.drools.io.ResourceFactory.newByteArrayResource(getRule()),
> ResourceType.DRL);
>
>        long t2 = System.currentTimeMillis();
>
>        KnowledgeBuilderErrors errors = kbuilder.getErrors();
>        if (errors.size() > 0) {
>            for (KnowledgeBuilderError error: errors) {
>                System.err.println(error);
>            }
>            throw new IllegalArgumentException("Could not parse
> knowledge.");
>        }
>        long t3 = System.currentTimeMillis();
>
>        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
>        long t4 = System.currentTimeMillis();
>
>        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
>        long t5 = System.currentTimeMillis();
>
>
>        Collection<KnowledgePackage> kpackages =
> kbase.getKnowledgePackages();
>                for (KnowledgePackage knowledgePackage : kpackages) {
>                        System.out.println("Package -------- " +
> knowledgePackage.getName());
>                        Collection<Rule> rules =
> knowledgePackage.getRules();
>                        for (Rule rule : rules) {
>                                System.out.println("****" + rule.getName());
>                        }
>                }
>        long t6 = System.currentTimeMillis();
>
>        System.out.println( (t11-t1) + " " + (t2-t11) + " " + ( t3-t2) + "
> " +
> ( t4-t3) + " " + ( t5-t4) + " " + ( t6-t5)+ " " );
>
>        return kbase;
>    }
>
> Based on the timing logs the code take majority (more than 80%) of time in
> only these two operations. Is there a way to make it faster ?
>
> KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
> kbuilder.add(
> org.drools.io.ResourceFactory.newByteArrayResource(getRule()),
> ResourceType.DRL);
>
> thanks.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Is-there-a-faster-way-of-doing-this-in-Drools-tp3973888.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
>



-- 
 - MyJourney @ http://salaboy.wordpress.com
 - Co-Founder @ http://www.jugargentina.org
 - Co-Founder @ http://www.jbug.com.ar

 - Salatino "Salaboy" Mauricio -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120509/35566c22/attachment.html 


More information about the rules-users mailing list