Description of problem: I have a set o simple rules with temporal operators. Rules contain only "when" section, the "then" section is empty. Inserting some amount of facts (events) and firing the rules takes much longer with beta4 (and current snapshot) comparing with beta3. See attached Maven based reproducer - the reproducer contains only after and before operators, but this slow down was also seen with other temporal operators. For example the execution time for the attached reproducer: - beta3: 20ms - beta4: 3000ms This issues was first seen with beta4 so it could be related to the new phreak algorithm. Version-Release number of selected component (if applicable): 6.0.0.Beta4 and current 6.0.0-SNAPSHOT How reproducible: Always Steps to Reproduce: 1. Run the attached reproducer (mvn test) 2. Change the version in pom.xml to beta3 and run it again. 3. Compare the times printed to stdout. Actual results: The execution time for beta4 (and current snapshot) is much longer comparing to beta3. Expected results: The execution time is same or better comparing to beta3.
Created attachment 768370 [details] Simple Maven based reproducer
KSession was slower in beta4, because of segment initialization is heavy. Mario has "proto" classed that initialization now, so after the first ksession, they should be quick to create.
The problem was not caused by phreak (that indeed is faster than rete), but by the fact that the default event processing mode has been mistakenly set to STREAM instead of CLOUD, so that test was running in STREAM mode on beta4. I fixed this.
So, should be the difference between running in CLOUD and STREAM mode that high? 20ms vs 3000ms? This seems not right to me. I will test it with 5.3.x to see if the difference is also there.
I ran the test with 5.3.1-P03 and the difference between CLOUD and STREAM mode is negligible. So the main problem is that the difference between these two processing options in Drools 6 is very high. I will also update the reproducer to include the code for running with 5.3.1.-P03.
Created attachment 768725 [details] Reproducer including both Drools5 and Drools6 projects. Added Maven reproducer that includes code for both Drools 5 and Drools 6. To run with CLOUD option, just use "mvn test", for running in STREAM mode use "mvn test -Ddrools.mode=stream".
I profiled the provided test case in STREAM mode and found that the culprit of this huge difference were 2 trace logging statements not guarded by a if ( log.isTraceEnabled() ) { ... } block. I conditioned those log statements in that way (together with some other I found doing a full text search) and now phreak is slightly faster than rete even in STREAM mode.
By the way I also added the possibility to pass a varargs of KieBaseOptions to the KieHelper when building the KieBase so, for example, now you can do: kieBase = kieHelper.build(PhreakOption.ENABLED, EventProcessingOption.STREAM);
Thanks for the quick fix Mario! Will retest asap. And btw thanks for adding the possibility to configure KieBase when using KieHelper, this is really useful.
Verified fixed on 6.0.0 master. I will close this bz once verified also in product build.
Verified fixed in ER2.