Hi and Thanks for your reply.
Yes I am creating the KieBase once (I believe). This is code example used in class constructor:
private KieBase initialiseKieBase(RuleResourceInfo ruleResourceInfo) {
log.info("Initialise KieBase");
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
kieModuleModel.newKieBaseModel(ruleBaseName)
.setDefault(true)
.setEqualsBehavior(EqualityBehaviorOption.EQUALITY);
kfs.writeKModuleXML(kieModuleModel.toXML());
//add rules to kfs
kfs.write(String.format("src/main/resources/%s.drl", ruleBaseName),
kieServices.getResources().newFileSystemResource(ruleResourceInfo.getMainRulesFile().toFile()));
if (ruleResourceInfo.getProceduralRulesFile() != null) {
kfs.write(String.format("src/main/resources/%s.drl", ruleBaseName + "_procedural"),
kieServices.getResources()
.newFileSystemResource(ruleResourceInfo.getProceduralRulesFile().toFile()));
}
log.info("Compiling rule base {}", ruleBaseName);
KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
checkErrors(results);
log.info("Creating Kie container...");
KieContainer kc = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
KieBaseConfiguration kieBaseConf = kieServices.newKieBaseConfiguration();
KieBase kieBase = kc.newKieBase(kieBaseConf);
log.info("Initialise KieBase.. Done");
return kieBase;
}
And KieSessions are created once per API request and disposed at the end of each request:
public void processRequest(Input) {
KieSession kieSession = kbase.newKieSession();
try {
log.info("Processing facts");
// fire rules;
} catch (Exception e) {
// handle ex
} finally {
if (kieSession != null) {
kieSession.dispose();
}
}
}
So memory shooting happens just while application starting (we can verify with the log messages
"Compiling rule base {}" and "Creating Kie container...") and doesn't get down after KieBase is created.
<<
KieBases can be large, depending on the number of rules.
<<
one question when you say it can be large does it get that large about 6G or more for ~50,000 rules?
Wondering if we put effort to migrate to drools 8.x and use executable model (if I could manage to make the migration) will that make any impact on memory footprint? documentation says it is faster and efficient but not sure about memory.
Also does breaking very large rules (rules with hundreds of conditions) into multiple smaller rules make any difference? probably not!
Regards