Configuring and Optimizing Drools

This section details various improvements that are implemented for Drools optimization and KIE Session pooling.

Drools Optimizations

Some classes shipped with Drools are modified to allow for performance optimizations as well as bug fixes:
  • ProjectClassLoader: Drools' ProjectClassLoader class leads to thread congestion. A patched version has been provided as a .class file (located in the ruleengine/resources/org/drools/core/common directory).
  • ChainedProperties: Drools ships with a ChainedProperties class that excessively reads from a properties file. A patched version has been provided as a .class file (located in the ruleengine/resources/org/kie/internal/utils directory).

Placing the .class files in the resources directory ensures that the platform classloader loads these classes instead of the classes provided in the Drools libraries. The Drools libraries are located in the ruleengine/lib directory.

KIE Session Pooling

Drools ships with a simple Knowledge Is Everything (KIE) session pooling mechanism. KIE session pooling can improve memory consumption because the sessions are reused.

By default, this pooling mechanism is disabled. The following system properties can be used in the local.properties file to enable and configure the pool:
ruleengine.kiesession.pool.enabled=true
ruleengine.kiesession.pool.initialcapacity=5
ruleengine.kiesession.pool.keep.only.one.version=true

Optimizing Memory Consumption of Drools KieModules

It is more likely to encounter performance issues related to high memory consumption or potential memory leaks of kieModules when publishing promotion rules and executing kieModules swapping with high concurrency in the cluster deployment mode.

It's recommended to Enable the following configuration by setting the value to true to avoid and resolve these performance issues.
ruleengine.remove.all.previous.versions.kiemodules.in.kierepository=false

The value of this configuration is false by default.

Addressing Infinite Loop Issues in Drools with Timeout Mechanism

When executing evaluations of promotion rules, there are extreme cases where the evaluation process gets stuck in an infinite loop. This occurs when the method doUpdatesReorderRightMemory is invoked within the class RuleNetworkEvaluator of Drools. This can result in excessive CPU consumptions and decreased performance.

To fix this issue, a timeout mechanism has been introduced in the method, which allows for the specification of a timeout value, measured in seconds. When this timeout is reached, the evaluation of rules is aborted to prevent the occurrence of potential infinite loops. Additionally, the timeout property is defined as configurable, enabling adjustment of the timeout value as necessary.
drools.rulenetworkevaluator.timeout=10

The default value for the timeout property is set to 10 seconds. It's possible to modify this value to align with the business requirements. It is important to note that in order for the new timeout value to take effect, a server restart is required.