droolskie

Stateful session memory management in Drools


Just have a general question regarding memory management when using "Stateful sessions" in Drools. For context, I'm specifically looking to use a ksession in "Stream" mode, together with fireUntilHalt() to process an infinite stream of events. Each event is timestamped, however I'm mainly writing rules using length-based windows notation (i.e. window:length()) and the from accumulate syntax for decision making.

The docs are a little vague though about how memory management works in this case. The docs suggest that using temporal operators the engine can automatically remove any facts/events that can no longer match. However, would this also apply to rules that only use the window:length()? Or would my system need to manually delete events that are no longer applicable, in order to prevent running OOM?


Solution

  • window:time() calculates expiration, so works for automatic removal. However, window:length() doesn't calculate expiration, so events would be retained.

    You can confirm the behaviour with my example: https://github.com/tkobayas/kiegroup-examples/tree/master/Ex-cep-window-length-8.32

    FYI) https://github.com/kiegroup/drools/blob/8.32.0.Final/drools-core/src/main/java/org/drools/core/rule/SlidingLengthWindow.java#L145

    You would need to explicitly delete them or set @expires (if it's possible for your application to specify expiration with time) to avoid OOME.

    Thank you for pointing that the document is not clear about it. I have filed a doc JIRA to explain it.

    https://issues.redhat.com/browse/DROOLS-7282