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?