与从内存中检索KieBase实例相比,执行Kiebase(从缓存中检索实例)花费更多时间来触发所有规则。 [英] Executing Kiebase (instance retrieved from cache) takes more time to fire all rules as compared to when KieBase instance is retrieved from in-memory

查看:208
本文介绍了与从内存中检索KieBase实例相比,执行Kiebase(从缓存中检索实例)花费更多时间来触发所有规则。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建知识库 KieBase 上,我们第一次将其实例存储在缓存中,以便我们可以使用此缓存的实例节省构建时间。我注意到当直接使用此实例x时。通常,触发所有规则所需的时间非常少,但是当我们使用缓存的实例时,触发所有规则将花费更多的时间。

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.

这里是<如果从内存中获取 KieBase 实例(即 KieBase 实例被直接使用)

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]

这里是时间在每次执行时从缓存(Redis)中获取 KieBase 实例时,由 kieSession.fireAllRules()捕获

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.

如果您注意到, KieBase 花费的时间更多

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

这种行为的原因是什么?如何确保从缓存中检索到的 KieBase 实例花费较少的时间来触发所有规则?

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();


推荐答案

不幸的是,不支持KieBase序列化。除了效果之外,您可能还会遇到意想不到的问题,因此请不要这样做(因此我不了解它为什么变慢)。您可以将KieBase存储在内存中。如果群集中有多个节点,请为每个JVM构建KieBase并将其存储在每个JVM的内存中。

Unfortunately, KieBase serialization is not supported. Apart from performance, you may hit unexpected issues so please refrain from doing that (so I don't go deep why it's slow). You can store KieBase in-memory. If you have multiple nodes in a cluster, please build KieBase per JVM and store it in-memory per JVM.

这篇关于与从内存中检索KieBase实例相比,执行Kiebase(从缓存中检索实例)花费更多时间来触发所有规则。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆