<div dir="ltr">Guys,<div><br></div><div>Splitting the problem into smaller ones and retracting facts totally solved the memory problem and also speed up the process.</div><div>I would like to thank you for your responsiveness and expertise.</div>

<div><br></div><div>I am truly amazed by the activity of this community, and Drools is an awesome piece of software !</div><div><br></div><div>Thanks,</div><div>Raphael</div><div><br></div></div><div class="gmail_extra">
<br>
<br><div class="gmail_quote">2014-03-20 21:57 GMT+01:00 Raphael Jolivet <span dir="ltr">&lt;<a href="mailto:raphael.jolivet@gmail.com" target="_blank">raphael.jolivet@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<p dir="ltr">Hmm, sure it makes sense. The operations and resources are independent. I think I can safely split the problem into smaller ones. I will try this approach.</p>
<p dir="ltr">Thanks for the tip</p>
<div class="gmail_quote">Le 20 mars 2014 20:51, &quot;Wolfgang Laun&quot; &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt; a écrit :<div><div class="h5"><br type="attribution">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I may fail to understand the fundamentals of this problem, but it seems<br>
to me that it doesn&#39;t have the dynamic requirements that would<br>
warrant a full &quot;blow up&quot; of all Resources and Operations at the same time.<br>
<br>
We have the 300 rules, and I&#39;m assuming that the pattern is the one<br>
shown in OP&#39;s mail: a Resource subset times an Operation subset. So,<br>
if you insert just one Resource (or Operation) fact together with<br>
all Operation (or Resource) facts and fire all rules, you&#39;ll get all Forbids<br>
for the one Resource with all Operations (or vice versa). Then, you<br>
retract the singleton and insert the next one, fire all rules, and so on.<br>
<br>
-W<br>
<br>
<br>
On 20/03/2014, Raphael Jolivet &lt;<a href="mailto:raphael.jolivet@gmail.com" target="_blank">raphael.jolivet@gmail.com</a>&gt; wrote:<br>
&gt; Thanks for you quick answer.<br>
&gt;<br>
&gt; Not yet,<br>
&gt;<br>
&gt; For that I will need to switch to fact insertion instead of Java Set.<br>
&gt; Do you think to will make a difference in the way the RETE Tree will be<br>
&gt; built ?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 2014-03-20 20:27 GMT+01:00 Mark Proctor &lt;<a href="mailto:mproctor@codehaus.org" target="_blank">mproctor@codehaus.org</a>&gt;:<br>
&gt;<br>
&gt;&gt; Did you try using the engine in equality mode? It will only ever allow<br>
&gt;&gt; one<br>
&gt;&gt; &quot;equal&quot; object to be inserted, others are just ignored.<br>
&gt;&gt;<br>
&gt;&gt; Mark<br>
&gt;&gt; On 20 Mar 2014, at 18:54, Raphael &lt;<a href="mailto:raphael.jolivet@gmail.com" target="_blank">raphael.jolivet@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Hi,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; In our project, we use Drools to compute forbidden allocations as input<br>
&gt;&gt; for<br>
&gt;&gt; &gt; an allocation problem  (for which we do not use Drools BTW).<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The constraint of the problem (forbidden operation for given resources)<br>
&gt;&gt; are<br>
&gt;&gt; &gt; expressed as drools rules.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; We have about<br>
&gt;&gt; &gt; -200 resources<br>
&gt;&gt; &gt; -700 operations<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Those are the Drools facts.<br>
&gt;&gt; &gt; We have about 200 Drools rules describing the forbidden allocations<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The problem here is that many rules produce duplicates forbids.<br>
&gt;&gt; &gt; For instance :<br>
&gt;&gt; &gt; Rule 1 may forbid Op1 on Res1 &amp; Res3<br>
&gt;&gt; &gt; Rule 2 may forbid Op1 on Res2 &amp; res3<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Currently the RHS of rules just insert forbids into a pure Java Set (no<br>
&gt;&gt; fact<br>
&gt;&gt; &gt; insertion).<br>
&gt;&gt; &gt; The Set takes care of avoiding duplicates, but still, we feel we could<br>
&gt;&gt; help<br>
&gt;&gt; &gt; Drools by giving him a hint that<br>
&gt;&gt; &gt; all rules are actually producing pairs of &lt;Resource, Allocation&gt; and<br>
&gt;&gt; that he<br>
&gt;&gt; &gt; should not try to produce them more than once.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Currently the structure of each rule looks like that :<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; when<br>
&gt;&gt; &gt; $resource : Resource(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; $operation : Operation(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; then<br>
&gt;&gt; &gt;  globalSet.add(Pair&lt;resrouce, operation&gt;)<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; With the size of the problem, we often end up with outOfMem/ GC limit.<br>
&gt;&gt; &gt; When analyzing memory dump, we see about<br>
&gt;&gt; &gt; 300.000 drools left tuple object.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I am not sure if we could help drools to reduce the Rete tree here.<br>
&gt;&gt; &gt; I mean, the allocation matrix is already : 200*700 = 140.000 cells.<br>
&gt;&gt; &gt; Drools only uses 2 nodes for each possible forbids, which seems already<br>
&gt;&gt; well<br>
&gt;&gt; &gt; optimized.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; We had several idea to improve that though, but we are not enough<br>
&gt;&gt; &gt; expert<br>
&gt;&gt; in<br>
&gt;&gt; &gt; the internal of the RETE algorithm to decide if that&#39;s a good way to go<br>
&gt;&gt; &gt; :<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 1) Insert forbids as facts in the RHS and check they are not already<br>
&gt;&gt; there<br>
&gt;&gt; &gt; in the LHS :<br>
&gt;&gt; &gt; when<br>
&gt;&gt; &gt; $resource : Resource(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; $operation : Operation(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; not Forbid(res=$resource, op=$operation)<br>
&gt;&gt; &gt; then<br>
&gt;&gt; &gt;  insert(Forbid($resource, $operation))<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2) Merge all rules in one big rule with a single RHS<br>
&gt;&gt; &gt; Is it possible to have something like :<br>
&gt;&gt; &gt; when<br>
&gt;&gt; &gt; // Rule 1<br>
&gt;&gt; &gt; ($resource : Resource(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; $operation : Operation(&lt;someconditions&gt;))<br>
&gt;&gt; &gt;  or<br>
&gt;&gt; &gt; // Rule 2<br>
&gt;&gt; &gt; ($resource : Resource(&lt;someconditions&gt;)<br>
&gt;&gt; &gt; $operation : Operation(&lt;someconditions&gt;))<br>
&gt;&gt; &gt; // Etc ...<br>
&gt;&gt; &gt; then<br>
&gt;&gt; &gt;  globalSet.add(Pair&lt;resrouce, operation&gt;)<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 3) Define a common RHS somewhere and tell Drools all rules use this<br>
&gt;&gt; &gt; one.<br>
&gt;&gt; &gt; Is there a possibility in Drools to define reusable RHS ? Would it help<br>
&gt;&gt; &gt; ?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 4) Any other idea ?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks in advance for your help.<br>
&gt;&gt; &gt; Brgds,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Raphael Jolivet<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; View this message in context:<br>
&gt;&gt; <a href="http://drools.46999.n3.nabble.com/Needs-advice-to-help-Drools-on-a-big-problem-and-avoid-GC-overhead-tp4028838.html" target="_blank">http://drools.46999.n3.nabble.com/Needs-advice-to-help-Drools-on-a-big-problem-and-avoid-GC-overhead-tp4028838.html</a><br>



&gt;&gt; &gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">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;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</blockquote></div></div></div>
</blockquote></div><br></div>