<br>   Cool, thanks for letting us know about the results.<br><br>   Regarding my suggestion, just to be clear, you would still use one stateful session for each of your requests. The only difference is that all sessions would be created from a shared kbase, meaning you would be able to stop building kbases from packages for each request.<br>
<br>   Take a look at the drools flow manual. I believe (without knowing more details about your project) that all you need is to use flow to coordinate which rules are allowed to fire and in which sequence for each of your requests.<br>
<br>    Edson<br><br><div class="gmail_quote">2009/12/22 malkhafaji <span dir="ltr">&lt;<a href="mailto:moe.alkhafaji@medcpu.com">moe.alkhafaji@medcpu.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Edson,<br>
<br>
I just want to report back that when I upgraded to M1, I was able to get<br>
through 20 or 30 more requests before I got the deadlock again. Then, I used<br>
the link you sent me and downloaded the snapshot branch, and was able to go<br>
through 875 requests (so far and running) without a deadlock!! It is working<br>
fine, and results are much much faster!!! I shaved over 200 ms per request<br>
and now I am averaging &lt; 30 ms per request in the engine!<br>
<br>
Once I am done with this software release, I want to explore what you<br>
suggested above. Can you direct me to documentations or some code that will<br>
show me how I can push multiple objects through the same drools instance<br>
(stateful) but each one will use a certain set of loaded packages? Those<br>
objects will come and go at different times (so the engine may be already<br>
running and it receives a new object.<br>
<br>
I am not looking for detailed code or anything, just basic code or a place<br>
on the documentation, or even an eclipse hello world project that you have.<br>
Much appreciated. Thank you again for your quick responses, and THE FIX!<br>
<div><div></div><div class="h5"><br>
<br>
Edson Tirelli-4 wrote:<br>
&gt;<br>
&gt;    Well, May 19th I guess you still have Drools 5.0.0. You should at least<br>
&gt; be using 5.0.1. Anyway, latest artifacts are here:<br>
&gt;<br>
&gt; <a href="https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/" target="_blank">https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/</a><br>
&gt;<br>
&gt; &quot;I am sure there are many ways to get it working on a sharing knowledge<br>
&gt; base,&quot;<br>
&gt;<br>
&gt;    Yes, and if what you have works for you, go for it. I am just<br>
&gt; mentioning<br>
&gt; that the simplest solution would be to load all rules in a single kbase<br>
&gt; and<br>
&gt; use ruleflow, by what you described in your 1-3 items.<br>
&gt;<br>
&gt;    Cheers,<br>
&gt;       Edson<br>
&gt;<br>
&gt; 2009/12/22 malkhafaji &lt;<a href="mailto:moe.alkhafaji@medcpu.com">moe.alkhafaji@medcpu.com</a>&gt;<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Edson,<br>
&gt;&gt;<br>
&gt;&gt; Thank you for replying to my question. I haven&#39;t tried the new release<br>
&gt;&gt; since<br>
&gt;&gt; May 19th of this year. Are you talking about the binaries (Drools<br>
&gt;&gt; 5.1.0.M1<br>
&gt;&gt; Binaries)? Should I go ahead and try that?<br>
&gt;&gt;<br>
&gt;&gt; To answer your question about not sharing KnowledgeBase for all requests,<br>
&gt;&gt; we<br>
&gt;&gt; have a very advanced logic outside of the rules engine. To give you some<br>
&gt;&gt; flavor, we have only one type of object per request. Each request will<br>
&gt;&gt; have<br>
&gt;&gt; its own data in that object. Now, we have wrapper code around the engine<br>
&gt;&gt; to<br>
&gt;&gt; do things like:<br>
&gt;&gt; 1. Last time this engine ran for this object, including what rules<br>
&gt;&gt; executed,<br>
&gt;&gt; etc.<br>
&gt;&gt; 2. Rules within packages loaded by default may load other packages on the<br>
&gt;&gt; fly because of which rules executed, and this only applies to that object<br>
&gt;&gt; that triggered the loading of those packages. For example, by default we<br>
&gt;&gt; have 1 package that is used for all objects. But object A may trigger a<br>
&gt;&gt; rule<br>
&gt;&gt; that loads another package which becomes available to it besides the main<br>
&gt;&gt; one. However, this new package is not yet available to all other objects.<br>
&gt;&gt; So, I did not know how I can load packages but only make them visible to<br>
&gt;&gt; some of the objects that I push through the session&#39;s knowledge base.<br>
&gt;&gt; 3. Our rules engine is either data driven (and the notification does not<br>
&gt;&gt; come from the rule, but outside the rule in some common logic), or time<br>
&gt;&gt; driven (run the engine again after n minutes because that is when our<br>
&gt;&gt; logic<br>
&gt;&gt; has determined that one of the conditions would turn true on a previously<br>
&gt;&gt; false condition potentially starting a chain of executions), etc.<br>
&gt;&gt;<br>
&gt;&gt; And other things. So, I found it to be much easier for me and my sanity<br>
&gt;&gt; to<br>
&gt;&gt; start using a new instance of a session (having its own knowledge base)<br>
&gt;&gt; per<br>
&gt;&gt; request. Those requests are very small and take no more than milliseconds<br>
&gt;&gt; on<br>
&gt;&gt; each object. So, I am using a stateful session that is alive for the life<br>
&gt;&gt; of<br>
&gt;&gt; the respective object. My objects are finite (you cannot have more than<br>
&gt;&gt; 1,000 in our memory), and they and their respective instances are very<br>
&gt;&gt; light<br>
&gt;&gt; weight and do not need more than a 1 GB of memory (mostly hovers around<br>
&gt;&gt; 500-600 MB).<br>
&gt;&gt;<br>
&gt;&gt; I am sure there are many ways to get it working on a sharing knowledge<br>
&gt;&gt; base,<br>
&gt;&gt; I just thought this way I don&#39;t need to worry about synchronizations or<br>
&gt;&gt; any<br>
&gt;&gt; other complicated logic on top of what we have. So, I made the decision.<br>
&gt;&gt;<br>
&gt;&gt; Please confirm that M1 binaries has your latest fix so I can get testing<br>
&gt;&gt; on<br>
&gt;&gt; it. Thanks!<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Edson Tirelli-4 wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    Hi,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    I fixed a problem related to deadlock when sharing packages among<br>
&gt;&gt; &gt; multiple kbases a couple weeks ago. Not sure if it is the same, but try<br>
&gt;&gt; &gt; trunk and let me know, plz.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    Meanwhile, I am curious why you can&#39;t simply create a kbase with all<br>
&gt;&gt; &gt; your<br>
&gt;&gt; &gt; rules and share the kbase among all your requests, just creating one<br>
&gt;&gt; &gt; session<br>
&gt;&gt; &gt; per request?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     Reason is that adding packages to a kbase for each request still<br>
&gt;&gt; adds<br>
&gt;&gt; &gt; unnecessary overhead to your application, and kbases are designed to be<br>
&gt;&gt; &gt; shared in such cases. If you need to orchestrate multiple execution<br>
&gt;&gt; paths<br>
&gt;&gt; &gt; for your rules, you could use rule flow or any other coordination<br>
&gt;&gt; &gt; mechanism.<br>
&gt;&gt; &gt; Finally, Rete is known by performing really well with increasing number<br>
&gt;&gt; of<br>
&gt;&gt; &gt; rules, since the performance is not dependent on the number of existing<br>
&gt;&gt; &gt; rules, but on the number of affected constraints.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    Just my .02c<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    Edson<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2009/12/22 malkhafaji &lt;<a href="mailto:moe.alkhafaji@medcpu.com">moe.alkhafaji@medcpu.com</a>&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hello,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I am trying to create multiple sessions, and for each session I will<br>
&gt;&gt; load<br>
&gt;&gt; &gt;&gt; one knowledge package representing one drl. Each drl may optionally<br>
&gt;&gt; load<br>
&gt;&gt; &gt;&gt; additional knowledge packages (drls). Since all sessions will be<br>
&gt;&gt; &gt;&gt; accessing<br>
&gt;&gt; &gt;&gt; the same list of knowledge packages, and since they take a long time<br>
&gt;&gt; to<br>
&gt;&gt; &gt;&gt; compile resources, I decided to create a Map with all possible<br>
&gt;&gt; knowledge<br>
&gt;&gt; &gt;&gt; packages that all sessions may use. That worked beautifully saving me<br>
&gt;&gt; &gt;&gt; compilation time (it is done at start up).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Now, here is how I am creating the static map:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; private static ConcurrentMap&lt;String, KnowledgePackage&gt;<br>
&gt;&gt; knowledgePackages<br>
&gt;&gt; &gt;&gt; =<br>
&gt;&gt; &gt;&gt; new<br>
&gt;&gt; &gt;&gt;                ConcurrentHashMap&lt;String, KnowledgePackage&gt;();<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Here is how I am initializing it:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;                KnowledgeBuilder kbuilder = null;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;                for (MedCPUKnowledgeBase medcpuKnowledgeBase :<br>
&gt;&gt; &gt;&gt; medcpuKnowledgeBases) {<br>
&gt;&gt; &gt;&gt;                        try {<br>
&gt;&gt; &gt;&gt;                                kbuilder =<br>
&gt;&gt; &gt;&gt; KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;                                // This call actually compiles the drl<br>
&gt;&gt; &gt;&gt; file.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; kbuilder.add(ResourceFactory.newClassPathResource(medcpuKnowledgeBase.getFileName()),<br>
&gt;&gt; &gt;&gt;                                                 ResourceType.DRL);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;                                KnowledgeBuilderErrors errors =<br>
&gt;&gt; &gt;&gt; kbuilder.getErrors();<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;                                if (errors.size() &gt; 0) {<br>
&gt;&gt; &gt;&gt;                                         .....<br>
&gt;&gt; &gt;&gt;                                } else {<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  knowledgePackages.put(medcpuKnowledgeBase.getFileName(),<br>
&gt;&gt; &gt;&gt;                                                        [the package<br>
&gt;&gt; just<br>
&gt;&gt; &gt;&gt; added above]);<br>
&gt;&gt; &gt;&gt;                                }<br>
&gt;&gt; &gt;&gt;                        } catch(Exception ex) {<br>
&gt;&gt; &gt;&gt;                                ....<br>
&gt;&gt; &gt;&gt;                                } else {<br>
&gt;&gt; &gt;&gt;                                        .....<br>
&gt;&gt; &gt;&gt;                                }<br>
&gt;&gt; &gt;&gt;                        }<br>
&gt;&gt; &gt;&gt;                }<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Each session will do this to get the pre-compiled KnowledgePackage:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; KnowledgePackage knowledgePackage = knowledgePackages.get(kb);<br>
&gt;&gt; &gt;&gt; ......<br>
&gt;&gt; &gt;&gt; Collection&lt;KnowledgePackage&gt; packages = new<br>
&gt;&gt; &gt;&gt; ArrayList&lt;KnowledgePackage&gt;();<br>
&gt;&gt; &gt;&gt; packages.add(knowledgePackage);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; // The problem is this guy (after a relatively small number of<br>
&gt;&gt; requests<br>
&gt;&gt; &gt;&gt; each<br>
&gt;&gt; &gt;&gt; opening a new session) just gets stuck!! It does not throw an<br>
&gt;&gt; exception<br>
&gt;&gt; &gt;&gt; and<br>
&gt;&gt; &gt;&gt; it does not return.<br>
&gt;&gt; &gt;&gt; this.knowledgeBase.addKnowledgePackages(packages);<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; When I did not share the KnowledgePackages like I did above, I was<br>
&gt;&gt; able<br>
&gt;&gt; &gt;&gt; to<br>
&gt;&gt; &gt;&gt; get thousands of requests with each having its own session,<br>
&gt;&gt; &gt;&gt; knowledgebase,<br>
&gt;&gt; &gt;&gt; and its own knowledge packages after they compile the respective drls.<br>
&gt;&gt; &gt;&gt; However, because this was slow compiling the same drls over and over<br>
&gt;&gt; &gt;&gt; again<br>
&gt;&gt; &gt;&gt; I<br>
&gt;&gt; &gt;&gt; switched to the design above which after only 20 or 30 requests it<br>
&gt;&gt; gets<br>
&gt;&gt; &gt;&gt; stuck on the line above. I still have a knowledgebase per session per<br>
&gt;&gt; &gt;&gt; request, but now I am sharing the knowledge packages.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I cannot find anywhere where it says that KnowledgePackage objects are<br>
&gt;&gt; &gt;&gt; not<br>
&gt;&gt; &gt;&gt; thread-safe (not safe to be shared between sessions/threads). Any idea<br>
&gt;&gt; &gt;&gt; why<br>
&gt;&gt; &gt;&gt; I<br>
&gt;&gt; &gt;&gt; am stuck on the line above? Thanks!<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; View this message in context:<br>
&gt;&gt; &gt;&gt; <a href="http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p96894.html" target="_blank">http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p96894.html</a><br>
&gt;&gt; &gt;&gt; Sent from the Drools - User mailing list archive at Nabble.com.<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt;  Edson Tirelli<br>
&gt;&gt; &gt;  JBoss Drools Core Development<br>
&gt;&gt; &gt;  JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&gt;&gt; <a href="http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p97452.html" target="_blank">http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p97452.html</a><br>
&gt;&gt; Sent from the Drools - User mailing list archive at Nabble.com.<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt;  Edson Tirelli<br>
&gt;  JBoss Drools Core Development<br>
&gt;  JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
--<br>
</div></div>View this message in context: <a href="http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p97506.html" target="_blank">http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p97506.html</a><br>
<div><div></div><div class="h5">Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>