Alex R
Alex R

Reputation: 11881

How do you profile a Drools application?

How can I find out how often each drools condition/consequence is being executed and how long it's taking?

The common JVM profilers are too low-level for this purpose, as the names of the internal drools methods won't tell you what rule they're executing.

Upvotes: 4

Views: 493

Answers (1)

laune
laune

Reputation: 31290

The question is essentially impossible to answer for condition evaluation. Patterns and constraints on left hand sides are not evaluated a unit (in the sense a Java method is a unit) but as a network of expressions, evaluated in small instalments whenever it is necessary. Moreover, constraints occurring in more than one condition may result in the same code, eliminating multiple evaluation. The necessity of evaluation depends on the insertion, deletion and modification of facts; the effort varies depending on the values being in these facts. All of this is a consequence of the underlying algorithm, originally Dr. Forgy's Rete and, in Drools 6.x, Phreaky, which apparently makes the situation even less straightforward by improving efficiency.

Benchmarking the conditions might be done by inserting facts of one class while varying their field values and timing this (considering the usual difficulties encountered with Java). Note that even this is treacherous, as the effort may depend on the current state of the Working Memory, i.e., the values of the facts of other classes that have been inserted. And you have to consider the effort required to reestablish the initial state - leaving facts in WM will eventually cause increased overhead due to memory mangagement.

The situation is somewhat better for constraint evaluation. kaskelotti's hint on using an event listener is noteworthy; rather than trying to time these short intervals, just count them. Also note that it may be good coding practice for many Drools applications to implement the right hand side as a (static) Java method: these can be unit tested (and benchmarked) more easily.

Upvotes: 2

Related Questions