<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">1) Any benchmark for the first minute or so, is pointless. The JVM will not have time to optimise its JIT.<div>2) About every 30s or so, there will be a slowdown as GC kicks in. You can alleviate (but not remove) this a little with the correct xmx, xms settings, and choosing the correct garbage collector. What those should be, depends on your usage of Drools, you will need to read up, and try different combinations. Certainly make sure you have -server set.</div><div><br></div><div><a href="http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html">http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html</a></div><div><a href="http://www.javaworld.com/article/2078645/java-se/jvm-performance-optimization--part-3--garbage-collection.html">http://www.javaworld.com/article/2078645/java-se/jvm-performance-optimization--part-3--garbage-collection.html</a></div><div><a href="http://www.javaworld.com/article/2078661/java-concurrency/jvm-performance-optimization--part-4--c4-garbage-collection-for-low-latency-java-ap.html">http://www.javaworld.com/article/2078661/java-concurrency/jvm-performance-optimization--part-4--c4-garbage-collection-for-low-latency-java-ap.html</a></div><div><br></div><div>Beyond that, welcome to the Java platform :)</div><div><br></div><div><br></div><div>Mark<br><div><div>On 30 Jan 2014, at 00:33, Harpreet Singh <<a href="mailto:harpreet2301@yahoo.com">harpreet2301@yahoo.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"><div>Hi,</div><div><br></div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">I have been trying to measure Drools' 5.5.0 performance for quite some time. I see that Drools' perform inconsistently in terms of CPU time.</div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Please see the below code
(modification of DroolsTest example):</div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">/*Code start*/</div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="background-color: transparent;">public class DroolsTest {</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public static final void main(String[] args) {</div><div style="background-color: transparent;">
try {</div><div style="background-color: transparent;"> // load up the knowledge base</div><div style="background-color: transparent;"> KnowledgeBase kbase = readKnowledgeBase();</div><div style="background-color: transparent;"> // go !</div><div style="background-color: transparent;"> for (int i = 0; i < 20; i++) {</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>Message message = new Message();</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>message.setMessage("Hello World");</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>message.setStatus(Message.HELLO);</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>long startTime = System.nanoTime();</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>FactHandle handle = ksession.insert(message);</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>ksession.fireAllRules();</div><div style="background-color: transparent;">
<span class="Apple-tab-span" style="white-space:pre">        </span>ksession.retract(handle);</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>System.out.println("Time taken is: " + (System.nanoTime()-startTime)/1000);</div><div style="background-color: transparent;"> <span class="Apple-tab-span" style="white-space:pre">        </span>ksession.dispose();</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"> } catch (Throwable t) {</div><div style="background-color: transparent;"> t.printStackTrace();</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> private static KnowledgeBase readKnowledgeBase() throws Exception {</div><div style="background-color: transparent;"> KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</div><div style="background-color: transparent;"> kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);</div><div style="background-color: transparent;"> KnowledgeBuilderErrors errors = kbuilder.getErrors();</div><div style="background-color: transparent;"> if (errors.size() > 0) {</div><div style="background-color: transparent;"> for (KnowledgeBuilderError error: errors) {</div><div style="background-color: transparent;">
System.err.println(error);</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"> throw new IllegalArgumentException("Could not parse knowledge.");</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"> KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();</div><div style="background-color: transparent;"> kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());</div><div style="background-color: transparent;"> return kbase;</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public static class Message {</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public static final int HELLO = 0;</div><div style="background-color: transparent;"> public static final int GOODBYE = 1;</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> private String message;</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> private int status;</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public String getMessage() {</div><div style="background-color: transparent;"> return this.message;</div><div style="background-color: transparent;"> }</div><div style="background-color:
transparent;"><br></div><div style="background-color: transparent;"> public void setMessage(String message) {</div><div style="background-color: transparent;"> this.message = message;</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public int getStatus() {</div><div style="background-color: transparent;"> return this.status;</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> public void setStatus(int status) {</div><div style="background-color: transparent;"> this.status = status;</div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"> }</div><div style="background-color: transparent;">}</div><div>/** Code end<span style="font-size: 12pt;">**/</span></div><div><span style="font-size: 12pt;"><br></span></div><div>I have just added timing code to the DroolsTest.java program (provided by JBoss) and I am using Sample.drl file (provided by JBoss). The rules get executed correctly but the timings that I see are:</div><div><br></div><div>Iteration 1: 103753 (we can ignore this as the classes get loaded during the first iteration)</div><div>Iteration 2: 861</div><div>Iteration 3: 744</div><div>Iteration 4: 1350<br></div><div>Iteration 5: 718<br></div><div>Iteration 6: 651<br></div><div>Iteration 7: 661<br></div><div>Iteration 8: 668<br></div><div>Iteration 9: 648<br></div><div>Iteration 10:
3564<br></div><div>Iteration 11: 911<br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>Iteration 12: 689</div><div>Iteration 13: 682<br></div><div>Iteration 14: 796<br></div><div>Iteration 15: 4236<br></div><div>Iteration 16: 774<br></div><div>Iteration 17: 772<br></div><div>Iteration 18: 722<br></div><div>Iteration 19: 713<br></div><div>Iteration 20: 697</div><div><br></div><div>I profiled it with Yourkit Profiler and the increase in time does not correspond to garbage collection. I also timed individual calls and found out that:</div><div>- ksession.insert: takes consistent time</div><div>- ksession.fireAllRules: inconsistent</div><div>- kbase.newStatefulKnowledgeSession: inconsistent</div><div><br></div><div>I see same inconsistency in performance when I integrate Drools with original project (which I can't share here). I also found that this has nothing to do with compiler
optimizations.</div><div><br></div><div><span style="font-size: 12pt;">Why is there inconsistent performance? </span>Is there anything that I am missing?<br></div><div><br></div><div>Thank you.</div><div><br></div><div><br></div><div><br></div></div></div>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users</blockquote></div><br></div></body></html>