Drools 5.1 memory issues

2019-09-05 01:08发布

问题:

Can drool 5.1 cause memory leak issues? We are using complex validation rules where we are calling java codes. Each request to backend load 2-3 drool files and new KnowledgeBase is created for each request.

Can anyone throw more light on this?

private void initRulesEngine() {
    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    if (kbuilder != null) {
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    }
}

public void executeRules(BaseUOW requestedUOW) {
    initRulesEngine();
    ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(requestedUOW);
    ksession.fireAllRules();
}

This is our code for Drool rules

回答1:

I did a lot of profiling and did not found any memory leak in Drools 5.1. If you are using stateful sessions, make sure you call dispose() after using them. Caching kbases is also recomended if possible, but creating them on demand should not leak memory anyway.

Other than that, it is just like any other java application. Use a profiler to find out what class (if any) is retaining your object instances in memory.