<div><br></div> Chris<div><br></div><div> That defines the expiration policy for ReconfigEvent, but it does not define the relationship between ReconfigEvent and DataReading. Imagine a timeline, dotted with ReconfigEvents... what your rule is saying is for each DataReading event, match it with all the "periods where there is no ReconfigEvent", as the lifetime of DataReading is infinity.</div>
<div><br></div><div> Maybe a simpler way of understanding it (without using the "not" for simplification) is think about this:</div><div><br></div><div>declare Man</div><div> @livesUpTo( 100 years )</div><div>
end</div><div><br></div><div>rule "marriage"</div><div>when</div><div> $w : Woman( age > 18 ) </div><div> $m : Man( )</div><div>then</div><div> // marry woman and man</div><div>end</div><div><br></div><div>
The rule above defines that each woman will merry every existing man, even if each of them only lives for 100 years.</div><div><br></div><div> Edson<br><br><div class="gmail_quote">2011/7/26 Chris Richmond <span dir="ltr"><<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><u></u>
<div bgcolor="#ffffff" text="#000000">
Edson,<br>
<br>
I was under the impression that this:<div class="im"><br>
<br>
declare ReconfigEvent<br>
@role( event )<br>
@expires ( 5s )<br>
end<br>
<br></div>
would cover that, meaning that every ReconfigEvent would expire
after 5s, thus causing to no longer be needed by the engine.<br>
<br>
Thanks,<br><font color="#888888">
Chris</font><div><div></div><div class="h5"><br>
<br>
On 7/25/2011 12:17 PM, Edson Tirelli wrote:
<blockquote type="cite">
<div><br>
</div>
Chris,
<div><br>
</div>
<div> I haven't tried your code, but just looking at the rule,
there is no temporal correlation between DataReading and
ReconfigEvent, so if I am not mistaken, that will create a
required interval of infinite time when the temporal reasoning
is applied, meaning the engine has to keep the readings in
memory forever. </div>
<div><br>
</div>
<div> Adding a temporal constraint on the ReconfigEvent pattern
on your rule or defining an explicit expiration policy for the
DataReadings are ways to work around that.</div>
<div><br>
</div>
<div> Edson<br>
<br>
<div class="gmail_quote">2011/7/26 Chris Richmond <span dir="ltr"><<a href="mailto:crichmond@referentia.com" target="_blank">crichmond@referentia.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
Hello<br>
<br>
I am performing a simple test of injecting an event every 1
millisecond<br>
like so:<br>
<br>
for (int x = 0; x < 100000; x++){<br>
DataReading dr = new DataReading("Reading " + x,
12.0f);<br>
myStream.insert(dr);<br>
ksession.fireAllRules();<br>
Thread.sleep(1);<br>
<br>
}<br>
<br>
<br>
The rule that evaluates this is simple. It basically delays
"then" for<br>
3s to see if a followup reading is inserted and makes sure
that no<br>
ReconfigEvent is active(5s expiration).<br>
<br>
So if a reading comes in and a followup reading is not
inserted within 3<br>
seconds and there is is not an existing ReconfigEvent event
alive, then<br>
it should output and insert a ReconfigEvent, essentially
disabling any<br>
DataReading action on those events for the next 5 seconds or
so. This<br>
all works just fine as expected.<br>
<br>
My question is, how come I don't get memory back when all
100,000 of my<br>
events have been inserted. Memory goes up slowly over the
course of<br>
insertions, which I can understand, but once that loop is
finished,<br>
memory never reduces, so essentially, the application will
eventually<br>
run out of memory after some time. I should not have to
explicitly<br>
remove/retract events should I? Shouldn't they be removed
from working<br>
memory as soon as they are no longer viable? What should I
be doing to<br>
reclaim memory from the session/knowledgebase?<br>
<br>
I have included the full Main program here and the
Sample.drl file below it.<br>
<br>
************FusionMain.java*****************<br>
<br>
package com.sample;<br>
<br>
import org.drools.KnowledgeBase;<br>
import org.drools.KnowledgeBaseConfiguration;<br>
import org.drools.KnowledgeBaseFactory;<br>
import org.drools.builder.KnowledgeBuilder;<br>
import org.drools.builder.KnowledgeBuilderError;<br>
import org.drools.builder.KnowledgeBuilderErrors;<br>
import org.drools.builder.KnowledgeBuilderFactory;<br>
import org.drools.builder.ResourceType;<br>
import org.drools.conf.EventProcessingOption;<br>
import org.drools.io.ResourceFactory;<br>
import org.drools.logger.KnowledgeRuntimeLogger;<br>
import org.drools.logger.KnowledgeRuntimeLoggerFactory;<br>
import org.drools.runtime.KnowledgeSessionConfiguration;<br>
import org.drools.runtime.StatefulKnowledgeSession;<br>
import org.drools.runtime.conf.ClockTypeOption;<br>
import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
<br>
<br>
public class FusionMain {<br>
<br>
@SuppressWarnings("restriction")<br>
public static void main(String[] args) {<br>
<br>
<br>
try {<br>
<br>
KnowledgeSessionConfiguration config =<br>
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
config.setOption( ClockTypeOption.get("realtime") );<br>
<br>
<br>
KnowledgeBase kbase;<br>
kbase = readKnowledgeBase();<br>
StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
<br>
WorkingMemoryEntryPoint myStream =<br>
ksession.getWorkingMemoryEntryPoint("My Stream");<br>
<br>
for (int x = 0; x < 100000; x++){<br>
DataReading dr = new DataReading("Reading " + x,
12.0f);<br>
myStream.insert(dr);<br>
ksession.fireAllRules();<br>
Thread.sleep(1);<br>
<br>
}<br>
<br>
} catch (Exception e) {<br>
// TODO Auto-generated catch block<br>
e.printStackTrace();<br>
}<br>
<br>
}<br>
<br>
@SuppressWarnings("restriction")<br>
private static KnowledgeBase readKnowledgeBase() throws
Exception {<br>
KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),<br>
ResourceType.DRL);<br>
KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
if (errors.size() > 0) {<br>
for (KnowledgeBuilderError error: errors) {<br>
System.err.println(error);<br>
}<br>
throw new IllegalArgumentException("Could not parse
knowledge.");<br>
}<br>
<br>
KnowledgeBaseConfiguration kbConfig =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
kbConfig.setOption( EventProcessingOption.STREAM );<br>
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<br>
<br>
return kbase;<br>
}<br>
<br>
<br>
}<br>
<br>
<br>
*********Sample.drl*************************<br>
<br>
package com.sample<br>
<br>
<br>
import java.util.Date;<br>
<br>
declare DataReading<br>
@role( event )<br>
end<br>
<br>
<br>
declare ReconfigEvent<br>
@role( event )<br>
@expires ( 5s )<br>
end<br>
<br>
<br>
<br>
rule "Wait for follup reading or no config"<br>
//lock-on-active<br>
when<br>
<br>
$dr: DataReading(reading > 10.0) from entry-point "My
Stream"<br>
not(DataReading(reading < 10.0, this after[0s,3s]
$dr) from<br>
entry-point "My Stream")<br>
not(ReconfigEvent() from entry-point "My Stream")<br>
<br>
then<br>
System.err.println("Action: " + new
Date(System.currentTimeMillis()));<br>
System.err.println("Data reading " + $dr.getName() + "
> 10");<br>
ReconfigEvent rce = new ReconfigEvent();<br>
entryPoints["My Stream"].insert( rce );<br>
<br>
end<br>
<br>
<br>
<br>
<br>
<br>
<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>
<br>
<br clear="all">
<br>
-- <br>
Edson Tirelli<br>
JBoss Drools Core Development<br>
JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
</div>
<pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</div></div></div>
<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>
<br></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>
</div>