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.<div>Cheers<br><br><div class="gmail_quote">On Wed, May 9, 2012 at 12:55 PM, soumya_sd <span dir="ltr"><<a href="mailto:soumya_sd@yahoo.com" target="_blank">soumya_sd@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've a use case where I need to create a rule dynamically every time the user<br>
sends a request.<br>
My current understanding of Drools is that you need to create a<br>
KnowledgeBuilder and then add the rules<br>
<br>
I'm creating the KnowledgeBase as follows.<br>
<br>
private static KnowledgeBase readKnowledgeBase() throws Exception {<br>
long t1 = System.currentTimeMillis();<br>
KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
long t11 = System.currentTimeMillis();<br>
<br>
<br>
kbuilder.add(<br>
org.drools.io.ResourceFactory.newByteArrayResource(getRule()),<br>
ResourceType.DRL);<br>
<br>
long t2 = System.currentTimeMillis();<br>
<br>
KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
if (errors.size() > 0) {<br>
for (KnowledgeBuilderError error: errors) {<br>
System.err.println(error);<br>
}<br>
throw new IllegalArgumentException("Could not parse<br>
knowledge.");<br>
}<br>
long t3 = System.currentTimeMillis();<br>
<br>
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
long t4 = System.currentTimeMillis();<br>
<br>
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
long t5 = System.currentTimeMillis();<br>
<br>
<br>
Collection<KnowledgePackage> kpackages =<br>
kbase.getKnowledgePackages();<br>
for (KnowledgePackage knowledgePackage : kpackages) {<br>
System.out.println("Package -------- " + knowledgePackage.getName());<br>
Collection<Rule> rules = knowledgePackage.getRules();<br>
for (Rule rule : rules) {<br>
System.out.println("****" + rule.getName());<br>
}<br>
}<br>
long t6 = System.currentTimeMillis();<br>
<br>
System.out.println( (t11-t1) + " " + (t2-t11) + " " + ( t3-t2) + " " +<br>
( t4-t3) + " " + ( t5-t4) + " " + ( t6-t5)+ " " );<br>
<br>
return kbase;<br>
}<br>
<br>
Based on the timing logs the code take majority (more than 80%) of time in<br>
only these two operations. Is there a way to make it faster ?<br>
<br>
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
kbuilder.add( org.drools.io.ResourceFactory.newByteArrayResource(getRule()),<br>
ResourceType.DRL);<br>
<br>
thanks.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Is-there-a-faster-way-of-doing-this-in-Drools-tp3973888.html" target="_blank">http://drools.46999.n3.nabble.com/Is-there-a-faster-way-of-doing-this-in-Drools-tp3973888.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><br clear="all"><div><br></div>-- <br> - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><div> - Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>
- Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br> <br> - Salatino "Salaboy" Mauricio -</div><br>
</div>