[rules-users] addKnowledgePackages Delay

Moe Alkhafaji moe.alkhafaji at medcpu.com
Mon May 3 11:22:47 EDT 2010


I got more information after debugging this. It seems like the time that
takes to load a KnowledgePackage increases as the number of KnowledgePackage
that I already have in my KnowledgeBase increases. So, my KB right now has
28 KPs, and that is when loading a new KP takes a long time. However, if I
have less KPs in my KB then loading will take much less.

What exactly happens when someone adds a new KP to an existing KB?
Considering that the KP is an already compiled set of rules. Why is this
dependent on the number of KPs in the KB? This is very frustrating because I
cannot find anything in the documentations or the historic threads on this
board. Maybe someone can shed some light on how this works behind the
scenes. Thank you.

On Mon, May 3, 2010 at 9:55 AM, Moe Alkhafaji <moe.alkhafaji at medcpu.com>wrote:

> Is there maybe a way to add those KnowledgePackages at startup time but
> somehow make them "hidden" and then just activate them when the KP needs to
> be available for execution and hiding it again (not available for execution)
> when they need to be unloaded?
>
> Thanks.
>
> Sent from my iPhone
>
> On May 3, 2010, at 9:36 AM, Moe Alkhafaji <moe.alkhafaji at medcpu.com>
> wrote:
>
> I see. Thanks Rajnikant. I appreciate the assistance. I hope there would be
> a way to maybe make this more internal to the KnowledgeBase object itself,
> or define another object for this type of caching instead of creating this
> complexity outside. Does anyone have another approach? Or is it basically
> that everyone is "putting" up with the delays of adding a new
> KnowledgePackage to an existing KnowledgeBase? Thanks.
>
> 2010/5/3 Rajnikant Gupta < <capricorn.raj at gmail.com>
> capricorn.raj at gmail.com>
>
>> As I said earlier It *may* or *may not* be relevant in your case. Usually
>> caching improves performance significantly in drools.
>>
>>  In case of our application it does so by a very significant factor.
>>
>> Regards,
>>
>> Rajnikant Gupta
>> <http://rkthinks.wordpress.com/>http://rkthinks.wordpress.com/
>>
>>
>>  2010/5/3 Moe Alkhafaji < <moe.alkhafaji at medcpu.com>
>> moe.alkhafaji at medcpu.com>
>>
>>>  Hmmm, so you are suggesting I keep caches all possible combinations of
>>> KnowledgePackages? If I have 100 possible KnowledgePackages and they are
>>> loaded and unloaded dynamically that means I will have to have 100 choose n
>>> where n goes from 1 to 100. That will make me go out of memory easy no?
>>>
>>> Thanks.
>>>
>>> Sent from my iPhone
>>>
>>> On May 3, 2010, at 2:07 AM, Rajnikant Gupta < <capricorn.raj at gmail.com>
>>> capricorn.raj at gmail.com> wrote:
>>>
>>>   It may look something like this:
>>>
>>> Map *knowledgeBaseCacheMap* = new HashMap();
>>>
>>> this.knowledgeBase = knowledgeBaseCacheMap.get("<SOME_IDENTIFIER>");
>>>
>>> if(this.knowledgeBase == null){
>>>    this.knowledgeBase.addKnowledgePackages(packages);
>>>    *knowledgeBaseCacheMap.put("<SOME_IDENTIFIER>", this.knowledgeBase)*
>>> }
>>>
>>> By doing this the packages get added to the knowledgeBase only for the
>>> first time. From second request onwards you get the same knowledgeBase each
>>> time without the need for adding the packages again.
>>>
>>> But this is valid only if you are not changing your rules. If your rules
>>> are changing from time to time, you may have to look at caching at more
>>> lower levels.
>>>
>>> I am not sure whether this can be helpful in your case but this is often
>>> helpful.
>>>
>>>
>>> Regards,
>>>
>>> Rajnikant Gupta
>>> <http://rkthinks.wordpress.com/> <http://rkthinks.wordpress.com/>
>>> http://rkthinks.wordpress.com/
>>>
>>>
>>>  2010/5/3 Moe Alkhafaji < <moe.alkhafaji at medcpu.com><moe.alkhafaji at medcpu.com>
>>> moe.alkhafaji at medcpu.com>
>>>
>>>>  Thanks for the reply. But I don't understand what you mean by caching
>>>> the KnowledgeBase. This is about adding a pre compiled KnowledgePackage to a
>>>> KnowledgeBase. So, how does caching a KnowledgeBase makes addition of new
>>>> KnowledgePackage faster? Please excuse my ignorance if I am not catching
>>>> what you are suggesting. Maybe a couple of lines of code to demonstrate your
>>>> suggestion would be greatly appreciated. Thanks.
>>>>
>>>> Sent from my iPhone
>>>>
>>>> On May 3, 2010, at 1:24 AM, Rajnikant Gupta < <capricorn.raj at gmail.com><capricorn.raj at gmail.com>
>>>> capricorn.raj at gmail.com> wrote:
>>>>
>>>>   Hi,
>>>>
>>>> Yes, adding packages to knowledgeBase does take some time. You can
>>>> probably try caching your knowledgeBase. By doing this all, but first,
>>>> requests should be significantly fast.
>>>>
>>>>
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Rajnikant Gupta
>>>>
>>>> <http://rkthinks.wordpress.com/> <http://rkthinks.wordpress.com/><http://rkthinks.wordpress.com/>
>>>> http://rkthinks.wordpress.com/
>>>>
>>>>
>>>> On Mon, May 3, 2010 at 11:36 AM, malkhafaji <<moe.alkhafaji at medcpu.com><moe.alkhafaji at medcpu.com><moe.alkhafaji at medcpu.com>
>>>> moe.alkhafaji at medcpu.com> wrote:
>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I am trying to add knowledge packages to an existing KnowledgeBase. My
>>>>> largest DRL file has 110 rules. I noticed that it may take up to 5
>>>>> seconds
>>>>> just to execute the following statement:
>>>>>
>>>>> this.knowledgeBase.addKnowledgePackages(packages);
>>>>>
>>>>> where "packages" is just a list of one knowledge package representing
>>>>> one
>>>>> drl. The nature of my rules is that I initially load a small set of
>>>>> rules
>>>>> and then at runtime my rules may load other DRLs. The problem is each
>>>>> DRL
>>>>> loading command (this.knowledgeBase.addKnowledgePackages(packages))
>>>>> takes a
>>>>> few seconds and I have no idea why. Although, all those DRLs are
>>>>> already
>>>>> compiled (at startup time). It is the line I pasted above that takes
>>>>> the
>>>>> longest time out of anything else I do.
>>>>>
>>>>> Any idea why just merely adding a KnowledgePackage list to a
>>>>> KnowledgeBase
>>>>> can take this much time? Do you guys have any suggestions on how I can
>>>>> reduce this time? I tried to create another dummy KnowledgeBase and get
>>>>> the
>>>>> KnowledgePackage from it at runtime and add that to my KnowedgeBase
>>>>> above
>>>>> (thinking that would reduce the time maybe), but not at all.
>>>>>
>>>>> Any ideas would be great. The API does not have much info on what that
>>>>> add
>>>>> method exactly does behind the scenes, and how I can get around the
>>>>> long
>>>>> delays. This is very frustrating to me, and I am not sure where to
>>>>> look.
>>>>> Thanks for ANY help at all.
>>>>> --
>>>>> View this message in context:
>>>>> <http://drools-java-rules-engine.46999.n3.nabble.com/addKnowledgePackages-Delay-tp772574p772574.html><http://drools-java-rules-engine.46999.n3.nabble.com/addKnowledgePackages-Delay-tp772574p772574.html><http://drools-java-rules-engine.46999.n3.nabble.com/addKnowledgePackages-Delay-tp772574p772574.html>
>>>>> http://drools-java-rules-engine.46999.n3.nabble.com/addKnowledgePackages-Delay-tp772574p772574.html
>>>>> Sent from the Drools - User mailing list archive at
>>>>> <http://nabble.com/> <http://nabble.com/>Nabble.com.
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>>  <rules-users at lists.jboss.org> <rules-users at lists.jboss.org><rules-users at lists.jboss.org>
>>>>> rules-users at lists.jboss.org
>>>>>  <https://lists.jboss.org/mailman/listinfo/rules-users><https://lists.jboss.org/mailman/listinfo/rules-users><https://lists.jboss.org/mailman/listinfo/rules-users>
>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>
>>>>
>>>>  _______________________________________________
>>>> rules-users mailing list
>>>> <rules-users at lists.jboss.org> <rules-users at lists.jboss.org>
>>>> rules-users at lists.jboss.org
>>>>  <https://lists.jboss.org/mailman/listinfo/rules-users><https://lists.jboss.org/mailman/listinfo/rules-users>
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> <rules-users at lists.jboss.org> <rules-users at lists.jboss.org>
>>>> rules-users at lists.jboss.org
>>>>  <https://lists.jboss.org/mailman/listinfo/rules-users><https://lists.jboss.org/mailman/listinfo/rules-users>
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>  _______________________________________________
>>> rules-users mailing list
>>> <rules-users at lists.jboss.org>rules-users at lists.jboss.org
>>>  <https://lists.jboss.org/mailman/listinfo/rules-users>
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> <rules-users at lists.jboss.org>rules-users at lists.jboss.org
>>>  <https://lists.jboss.org/mailman/listinfo/rules-users>
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>>  <rules-users at lists.jboss.org>rules-users at lists.jboss.org
>>  <https://lists.jboss.org/mailman/listinfo/rules-users>
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> Moe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100503/d8197058/attachment.html 


More information about the rules-users mailing list