0

I have implemented a rules engine based on drools (v7.25). The users dynamically add, update, and delete the rules.

The application could be expanded further and currently includes over 15000 rules. These rules are distributed evenly throughout several files even though they are part of the same package.

The application was initially functioning properly, but as the number of rules increased, the add and update performance of the rules has decreased noticeably.

For instance, it only takes the KieBuilder 300ms to build the KieBases when there are up to 1000 rules. But now, the same process can take up to 38000ms.

Here is a sample of my code for your reference:

    List<CustomerRule> customerRules = rulesBuilder.getCustomerRules(customerId);
    if (!customerRules.isEmpty()) {
        kieFileSystem.write(rulesBuilder.getDRLFilePath(customerId),
                rulesBuilder.getRulesFileData(customerId, customerRules));
    }
    KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll();
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        log.error(results.getMessages());
        return;
    }
    results = ((KieContainerImpl) kieContainer).updateToKieModule((InternalKieModule) kieBuilder.getKieModule());
    if (results.hasMessages(Message.Level.ERROR)) {
        log.error(results.getMessages());
        return;
    }
    kieContainer.dispose();

Is there a way to improve the re-building process of the KieBases? What are the best practises I should take into account?

Chinmay jain
  • 979
  • 1
  • 9
  • 20
  • At the end of the day, the more code you have, the longer it takes to compile and load. You might be able to eke out some performance improvements by increasing your CPU, but this is an expensive fix and not sustainable long-term. – Roddy of the Frozen Peas Nov 30 '22 at 15:29
  • @RoddyoftheFrozenPeas But you cannot limit the size of the code when you have 15000 rules. Is there a way to divide the rules in a way that only a subset of them could be loaded when changed? I don't know but something like modules. – Chinmay jain Jan 19 '23 at 07:36
  • You mean something like KieBases? – Roddy of the Frozen Peas Jan 19 '23 at 07:41

0 Answers0