<br>   Well, May 19th I guess you still have Drools 5.0.0. You should at least be using 5.0.1. Anyway, latest artifacts are here:<br><br><a href="https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/">https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/</a><br>
<br>&quot;I am sure there are many ways to get it working on a sharing knowledge base,&quot;<br><br>   Yes, and if what you have works for you, go for it. I am just mentioning that the simplest solution would be to load all rules in a single kbase and use ruleflow, by what you described in your 1-3 items.<br>
<br>   Cheers,<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>
Thank you for replying to my question. I haven&#39;t tried the new release since<br>
May 19th of this year. Are you talking about the binaries (Drools 5.1.0.M1<br>
Binaries)? Should I go ahead and try that?<br>
<br>
To answer your question about not sharing KnowledgeBase for all requests, we<br>
have a very advanced logic outside of the rules engine. To give you some<br>
flavor, we have only one type of object per request. Each request will have<br>
its own data in that object. Now, we have wrapper code around the engine to<br>
do things like:<br>
1. Last time this engine ran for this object, including what rules executed,<br>
etc.<br>
2. Rules within packages loaded by default may load other packages on the<br>
fly because of which rules executed, and this only applies to that object<br>
that triggered the loading of those packages. For example, by default we<br>
have 1 package that is used for all objects. But object A may trigger a rule<br>
that loads another package which becomes available to it besides the main<br>
one. However, this new package is not yet available to all other objects.<br>
So, I did not know how I can load packages but only make them visible to<br>
some of the objects that I push through the session&#39;s knowledge base.<br>
3. Our rules engine is either data driven (and the notification does not<br>
come from the rule, but outside the rule in some common logic), or time<br>
driven (run the engine again after n minutes because that is when our logic<br>
has determined that one of the conditions would turn true on a previously<br>
false condition potentially starting a chain of executions), etc.<br>
<br>
And other things. So, I found it to be much easier for me and my sanity to<br>
start using a new instance of a session (having its own knowledge base) per<br>
request. Those requests are very small and take no more than milliseconds on<br>
each object. So, I am using a stateful session that is alive for the life of<br>
the respective object. My objects are finite (you cannot have more than<br>
1,000 in our memory), and they and their respective instances are very light<br>
weight and do not need more than a 1 GB of memory (mostly hovers around<br>
500-600 MB).<br>
<br>
I am sure there are many ways to get it working on a sharing knowledge base,<br>
I just thought this way I don&#39;t need to worry about synchronizations or any<br>
other complicated logic on top of what we have. So, I made the decision.<br>
<br>
Please confirm that M1 binaries has your latest fix so I can get testing on<br>
it. Thanks!<br>
<div><div></div><div class="h5"><br>
<br>
Edson Tirelli-4 wrote:<br>
&gt;<br>
&gt;    Hi,<br>
&gt;<br>
&gt;    I fixed a problem related to deadlock when sharing packages among<br>
&gt; multiple kbases a couple weeks ago. Not sure if it is the same, but try<br>
&gt; trunk and let me know, plz.<br>
&gt;<br>
&gt;    Meanwhile, I am curious why you can&#39;t simply create a kbase with all<br>
&gt; your<br>
&gt; rules and share the kbase among all your requests, just creating one<br>
&gt; session<br>
&gt; per request?<br>
&gt;<br>
&gt;     Reason is that adding packages to a kbase for each request still adds<br>
&gt; unnecessary overhead to your application, and kbases are designed to be<br>
&gt; shared in such cases. If you need to orchestrate multiple execution paths<br>
&gt; for your rules, you could use rule flow or any other coordination<br>
&gt; mechanism.<br>
&gt; Finally, Rete is known by performing really well with increasing number of<br>
&gt; rules, since the performance is not dependent on the number of existing<br>
&gt; rules, but on the number of affected constraints.<br>
&gt;<br>
&gt;    Just my .02c<br>
&gt;<br>
&gt;    Edson<br>
&gt;<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; Hello,<br>
&gt;&gt;<br>
&gt;&gt; I am trying to create multiple sessions, and for each session I will load<br>
&gt;&gt; one knowledge package representing one drl. Each drl may optionally load<br>
&gt;&gt; additional knowledge packages (drls). Since all sessions will be<br>
&gt;&gt; accessing<br>
&gt;&gt; the same list of knowledge packages, and since they take a long time to<br>
&gt;&gt; compile resources, I decided to create a Map with all possible knowledge<br>
&gt;&gt; packages that all sessions may use. That worked beautifully saving me<br>
&gt;&gt; compilation time (it is done at start up).<br>
&gt;&gt;<br>
&gt;&gt; Now, here is how I am creating the static map:<br>
&gt;&gt;<br>
&gt;&gt; private static ConcurrentMap&lt;String, KnowledgePackage&gt; knowledgePackages<br>
&gt;&gt; =<br>
&gt;&gt; new<br>
&gt;&gt;                ConcurrentHashMap&lt;String, KnowledgePackage&gt;();<br>
&gt;&gt;<br>
&gt;&gt; Here is how I am initializing it:<br>
&gt;&gt;<br>
&gt;&gt;                KnowledgeBuilder kbuilder = null;<br>
&gt;&gt;<br>
&gt;&gt;                for (MedCPUKnowledgeBase medcpuKnowledgeBase :<br>
&gt;&gt; medcpuKnowledgeBases) {<br>
&gt;&gt;                        try {<br>
&gt;&gt;                                kbuilder =<br>
&gt;&gt; KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
&gt;&gt;<br>
&gt;&gt;                                // This call actually compiles the drl<br>
&gt;&gt; file.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; kbuilder.add(ResourceFactory.newClassPathResource(medcpuKnowledgeBase.getFileName()),<br>
&gt;&gt;                                                 ResourceType.DRL);<br>
&gt;&gt;<br>
&gt;&gt;                                KnowledgeBuilderErrors errors =<br>
&gt;&gt; kbuilder.getErrors();<br>
&gt;&gt;<br>
&gt;&gt;                                if (errors.size() &gt; 0) {<br>
&gt;&gt;                                         .....<br>
&gt;&gt;                                } else {<br>
&gt;&gt;<br>
&gt;&gt;  knowledgePackages.put(medcpuKnowledgeBase.getFileName(),<br>
&gt;&gt;                                                        [the package just<br>
&gt;&gt; added above]);<br>
&gt;&gt;                                }<br>
&gt;&gt;                        } catch(Exception ex) {<br>
&gt;&gt;                                ....<br>
&gt;&gt;                                } else {<br>
&gt;&gt;                                        .....<br>
&gt;&gt;                                }<br>
&gt;&gt;                        }<br>
&gt;&gt;                }<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Each session will do this to get the pre-compiled KnowledgePackage:<br>
&gt;&gt;<br>
&gt;&gt; KnowledgePackage knowledgePackage = knowledgePackages.get(kb);<br>
&gt;&gt; ......<br>
&gt;&gt; Collection&lt;KnowledgePackage&gt; packages = new<br>
&gt;&gt; ArrayList&lt;KnowledgePackage&gt;();<br>
&gt;&gt; packages.add(knowledgePackage);<br>
&gt;&gt;<br>
&gt;&gt; // The problem is this guy (after a relatively small number of requests<br>
&gt;&gt; each<br>
&gt;&gt; opening a new session) just gets stuck!! It does not throw an exception<br>
&gt;&gt; and<br>
&gt;&gt; it does not return.<br>
&gt;&gt; this.knowledgeBase.addKnowledgePackages(packages);<br>
&gt;&gt;<br>
&gt;&gt; When I did not share the KnowledgePackages like I did above, I was able<br>
&gt;&gt; to<br>
&gt;&gt; get thousands of requests with each having its own session,<br>
&gt;&gt; knowledgebase,<br>
&gt;&gt; and its own knowledge packages after they compile the respective drls.<br>
&gt;&gt; However, because this was slow compiling the same drls over and over<br>
&gt;&gt; again<br>
&gt;&gt; I<br>
&gt;&gt; switched to the design above which after only 20 or 30 requests it gets<br>
&gt;&gt; stuck on the line above. I still have a knowledgebase per session per<br>
&gt;&gt; request, but now I am sharing the knowledge packages.<br>
&gt;&gt;<br>
&gt;&gt; I cannot find anywhere where it says that KnowledgePackage objects are<br>
&gt;&gt; not<br>
&gt;&gt; thread-safe (not safe to be shared between sessions/threads). Any idea<br>
&gt;&gt; why<br>
&gt;&gt; I<br>
&gt;&gt; am stuck on the line above? Thanks!<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&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; 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-tp96894p97452.html" target="_blank">http://n3.nabble.com/Sessions-Sharing-KnowledgeBase-tp96894p97452.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>