<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">crichmond@referentia.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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">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">www.jboss.com</a><br>
</div>