Compiled resource objects leak in BRMS KnowledgeAgent

Solution Unverified - Updated

Environment

  • Red Hat JBoss BRMS
    • 5.3.1

Issue

  • OutOfMemoryError is presented in a BRMS application which has KnowledgeAgent looking at DRL files in a directory and those files are sometimes updated. In the heap dump, multiple org.drools.rule.DialectRuntimeRegistry/org.drools.rule.JavaDialectRuntimeData$PackageClassLoader/org.drools.rule.JavaDialectRuntimeData/org.drools.rule.MVELDialectRuntimeData objects are occupying the large part.

Resolution

  • There are 2 workarounds for this issue:
    1. Update the timestamp of all files under the directory which changeset looks at so KnowledgeAgentImpl.registeredResources will be fully updated. This can be done by touch *.drl under the directory in Linux. This operation should be automated periodically (e.g. once per hour) or every time you update a DRL file.

    2. Use newInstance=false for KnowledgeAgent:

       kagentConf.setProperty( "drools.agent.newInstance", "false" );
       knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("ReceiverConfigurationKAgent", kagentConf);
      

Root Cause

  • This content is not included.Bug 1067841 - Compiled resource objects leak in KnowledgeAgentImpl.registeredResources
  • Conditions for this bug:
    1. ChangeSet which points at a directory for DRL files
    2. Those DRL files have rules for the same package
    3. newInstance=true
  • KnowledgeAgentImpl.registeredResources has entries for each DRL files under the directory and holds org.drools.rule.Rule objects which lead to compiled resource objects like org.mvel2.compiler.CompiledExpression, org.drools.rule.DialectRuntimeRegistry, etc.
  • When one DRL file in the directory is updated, the package and kbase is fully updated and the entry in KnowledgeAgentImpl.registeredResources is updated as well. But other entries still retain old org.drools.rule.Rule objects hence related compiled resource objects will not be garbage collected.
  • Condition 1 is not mandatory. This issue can happen when KnowledgeAgent is looking at multiple resources for the same package.

Diagnostic Steps

  1. Capture a heap dump. If multiple org.drools.rule.DialectRuntimeRegistry / org.drools.rule.JavaDialectRuntimeData$PackageClassLoader / org.drools.rule.JavaDialectRuntimeData / org.drools.rule.MVELDialectRuntimeData objects are occupying the heap, it would hit this KCS solution.
  2. Use Eclipse Memory Analyzer Tool feature 'path to GC' to reach the root object. It should be KnowledgeAgentImpl.registeredResources.
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.