Could anyone explain, why Drools engine still requires source .drl files even if cached pre-compiled KIE bases already created and deployed with kie-maven-plugin? Is it possible to use only pre-compiled cache files? We are using Drools 6.2.0.Final and kie-maven-plugin to create pre-compiled KIE bases. Generated .jar file contains binary kbase.cache files for every KIE base AND corresponding .drl source files. KIE bases loading fails if we try to remove source .drl file from the generated .jar. We have 6000+ rules in our KIE bases. That is why time to load all KIE bases is significant. Drools engine spends comparable amount of time to load cached KIE bases and source .drl files during the "kieContainer.getKieBase("kie base name")" invocation. That is why removing .drl files will allow us to load KIE bases much faster. Why do we still need to keep source .drl files? Thank you.
Asked
Active
Viewed 2,699 times
2 Answers
3
I have received the answer from KIE dev team lead: "The cache is for the .class compilations. It still needs the DRL to build the rules and wire the pre-compiled .class files. It’s done this way as in general the parser and rule builders not too intensive, but .class generation is." https://groups.google.com/forum/#!topic/drools-usage/XqzfBvpdjSg Thank you.

Serge
- 111
- 2
- 9
1
A simple approach is to compile the DRL files, serialize the resulting KieBase put the file wherever you want it. Then, simply deserialize and create your session, and off you go.
Part One:
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
/*** repeat
FileInputStream fis = new FileInputStream( "simple/simple.drl" );
kfs.write( "src/main/resources/simple.drl",
kieServices.getResources().newInputStreamResource( fis ) );
/** until exhausted **/
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( "### errors ###" );
}
KieContainer kieContainer =
kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );
KieBase kieBase = kieContainer.getKieBase();
FileOutputStream fos = new FileOutputStream( BASEPATH );
ObjectOutputStream oos = new ObjectOutputStream( fos );
oos.writeObject( kieBase );
oos.close();
Part Two:
FileInputStream fis = new FileInputStream( BASEPATH );
ObjectInputStream ois = new ObjectInputStream( fis );
KieBase kieBase = (KieBase)ois.readObject();
kieSession = kieBase1.newKieSession();

laune
- 31,114
- 3
- 29
- 42
-
Thank you. But this is not what I have asked. We did a similar thing before, when Drools engine did not have kie-maven-plugin. We have multiple maven modules with drools and it is a great feature to see all compilation errors during the maven compile/package phase.But if technology suggests more clear approach, we would like to use it. My question is, why do we still need to have .drl files inside the jar with pre-compiles KIE bases if we use standard Drools tools? And one more thing - now we use configuration approach with kmodule.xml files instead of loading .drl files directly. – Serge Oct 12 '15 at 14:10
-
Perhaps someone will tell you that this feature hasn't been implemented yet and that you should feel free to submit a pull request. Also, I have found it easier to use the API to get what I want rather than try and grope through a tangle of undocumentation. You can get all the errors from the snippet "Part One". – laune Oct 12 '15 at 14:45
-
"Perhaps someone will tell you that this feature hasn't been implemented yet and that you should feel free to submit a pull request" - it will be an acceptable answer for me, if it will be an official answer from Drools DEV team. In that case we will try to create a suitable workaround. But I did not see anything like this in the official sources, that's why I suppose it should work from the box. Thank you. – Serge Oct 12 '15 at 16:17
-
1If Ambrose Bierce would write his "Dictionary" today, I'm sure he would add an entry **Documentation** *Something that is written later, and never read.* – laune Oct 12 '15 at 16:28
-
@laune Using cached KieBase instance, takes more time to fireAllRules then using instance directly. Any idea why is that so ? Problem is described here: https://stackoverflow.com/questions/60200522/executing-kiebase-instance-retrieved-from-cache-takes-more-time-to-fire-all-ru – user Feb 14 '20 at 06:17