javadroolsrule-enginecomplex-event-processingdrools-fusion

Drools Fusion: measure performance


I want to measure the performance of drools based on the number on rules and the complexity of the rules. I therefore need to measure the time it takes to handle the events. I want to write a simple test like this:

long start = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
    insertHeartRate(150, 0, macAddress);
    ksession.fireAllRules();
}
long stop = System.currentTimeMillis();
System.out.println("Running time: " + (stop - start));

The problem I'm facing is that this doesn't work since you can insert a much as events you want and drools will handle them later. So the timing of this part is always less then a second obviously. So my question is how can I call long stop = System.currentTimeMillis() after all the events are handled?


Solution

  • fireAllRules returns after everything has happened. So the code you have posted will indeed measure the elapsed time for inserting those events, and for firing all triggered rules.

    If your rules start any timers which will execute later: that's another matter. Also, you are addressing Fusion: those events will not arrive according to a tight loop, and timestamps and window:time and temporal operators: nothing will work as anticipated in your rules.

    If there are no temporal operators, or window:time, you can measure the time it takes to insert facts first, and measure the duration of fireAllRules.

    All is highly dependent on Java's JIT, GC behaviour and some details of your CPU...

    Edit After looking at your code I can add another recommendation. Make sure that you have a sequential sequence of events bracketing insertions and rule executions. Either run everything - inserts and fireAllRules, once or repeatedly - in one thread and measure the time before and after. Or, run fireUntilHalt in one thread, measure the time and insert in another thread. Now, to see when everything has died down after the last insert, you'll have to construct something to catch that moment. One way would be to insert some special fact, to trigger a rule with very low salience, and measure the end time in its consequence.