Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-7220

Memory leak when using DMNRuntime API with org.kie.dmn.compiler.execmodel=true

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.74.0.Final
    • 7.73.0.Final
    • dmn engine
    • None

      Hello, we are using DMNRuntime API with the org.kie.dmn.compiler.execmodel property set to true, here is a code snippet:

      // singleton, shared between multiple threads
      class RuleService {
         // kieContainer = KieServices.Factory.get().getKieClasspathContainer()
         // KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class)
         private final DMNRuntime dmnRuntime;
         private final DMNModel dmnModel;
         
         Object evaluateRule(SomeBean input) {
             var context = dmnRuntime.newContext();
             context.set("input", input);
             var result = dmnRuntime.evaluateByName(dmnModel, context, "someDecision");
             return result.getDecisionResultByName("someDecision").getResult();
         }
      }
      

      RuleService is a singleton and the evaluateRule method is invoked frequently from different threads that handle incoming requests. We are observing that the committed heap memory rises over time and never goes down. Heap dump shows that the DMNModel instance accumulates references to StatefulKnowledgeSessions (see attached screenshots)

      With org.kie.dmn.compiler.execmodel set to false this issue goes away - there are no leaks.

      Looks like the root cause is that the executor instance is not disposed here: https://github.com/kiegroup/drools/blob/7.73.0.Final/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/execmodelbased/AbstractModelEvaluator.java#L76

              tzimanyi@redhat.com Tibor Zimányi
              ddavidyuk Dmitry Davidyuk (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: