1) Any benchmark for the first minute or so, is pointless. The JVM will not have time to optimise its JIT.
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.

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
http://www.javaworld.com/article/2078645/java-se/jvm-performance-optimization--part-3--garbage-collection.html
http://www.javaworld.com/article/2078661/java-concurrency/jvm-performance-optimization--part-4--c4-garbage-collection-for-low-latency-java-ap.html

Beyond that, welcome to the Java platform :)


Mark
On 30 Jan 2014, at 00:33, Harpreet Singh <harpreet2301@yahoo.com> wrote:

Hi,

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.

Please see the below code (modification of DroolsTest example):

/*Code start*/

public class DroolsTest {

    public static final void main(String[] args) {
        try {
            // load up the knowledge base
            KnowledgeBase kbase = readKnowledgeBase();
            // go !
            for (int i = 0; i < 20; i++) {
            Message message = new Message();
            message.setMessage("Hello World");
            message.setStatus(Message.HELLO);
            long startTime = System.nanoTime();
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
            FactHandle handle = ksession.insert(message);
            ksession.fireAllRules();
            ksession.retract(handle);
            System.out.println("Time taken is: " + (System.nanoTime()-startTime)/1000);
            ksession.dispose();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    private static KnowledgeBase readKnowledgeBase() throws Exception {
        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error: errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse knowledge.");
        }
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        return kbase;
    }

    public static class Message {

        public static final int HELLO = 0;
        public static final int GOODBYE = 1;

        private String message;

        private int status;

        public String getMessage() {
            return this.message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public int getStatus() {
            return this.status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

    }
}
/** Code end**/

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:

Iteration 1: 103753 (we can ignore this as the classes get loaded during the first iteration)
Iteration 2: 861
Iteration 3: 744
Iteration 4: 1350
Iteration 5: 718
Iteration 6: 651
Iteration 7: 661
Iteration 8: 668
Iteration 9: 648
Iteration 10: 3564
Iteration 11: 911
Iteration 12: 689
Iteration 13: 682
Iteration 14: 796
Iteration 15: 4236
Iteration 16: 774
Iteration 17: 772
Iteration 18: 722
Iteration 19: 713
Iteration 20:  697

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:
- ksession.insert: takes consistent time
- ksession.fireAllRules: inconsistent
- kbase.newStatefulKnowledgeSession: inconsistent

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.

Why is there inconsistent performance? Is there anything that I am missing?

Thank you.



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users