Executing Kiebase (instance retrieved from cache) takes more time to fire all rules as compared to when KieBase instance is retrieved from in-memory

≡放荡痞女 提交于 2020-03-04 17:20:58

问题


On builiding knowledge base KieBase for the first time, we are storing its instance in cache so that we can save build time by using this cached instance. I noticed that when this instance is directly used x no. of times, it takes very very less time to fire all rules , BUT when we use cached instance then firing all rules takes more time.

Here is the time taken by kieSession.fireAllRules() when KieBase instance is taken from in-memory (i.e. KieBase instance is used directly)

min: 0 ms, max: 184 ms, avg: 7 ms  
Individual execution time: [184, 2, 15, 1, 1, 2, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 2, 5, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1]

Here is the time taken by kieSession.fireAllRules() when KieBase instance is taken from cache (Redis) in each execution

min: 35 ms, max: 152 ms, avg: 51 ms  
Individual execution time:  [152, 42, 45, 51, 40, 79, 56, 42, 48, 42, 44, 44, 69, 38, 40, 39, 57, 40, 61, 53, 35, 41, 43, 45, 51, 43, 48, 41, 43, 60]

//NOTE: This does not include cache fetch time. It only reflects the time taken (in ms) by function `fireAllRules` of class `KieSession`.

In above example, I have taken very less no. of rules but in actual I have thousands of rules.

If you notice, the time taken is more when KieBase instance used is the one retrieved from Cache.

What can be the reason for such behaviour? How do I make sure that the KieBase instance retrieved from Cache takes less time to fire all rules ?

KieSession kieSession = kbase.newKieSession();
kieSession.insert(...);
kieSession.fireAllRules();
kieSession.dispose();

来源:https://stackoverflow.com/questions/60200522/executing-kiebase-instance-retrieved-from-cache-takes-more-time-to-fire-all-ru

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!