Wolfgang,
the code to reproduce is below. I'm hoping to process between 20k and 50k events through Drools per second thus the extreme high-throughput testing. I could settle for a single Drools node handling only say 5K per second IFF I could cluster Drools but I've not yet found a way to distribute workload across an active-active Drools cluster (seems there is no such thing?).
Since you're recommendation I've shifted to using Drools 5.3 just FYI:
### Average.java ###
package drools53fusioneval;
import java.io.IOException;
import java.util.Random;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.conf.EventProcessingOption;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
class AvgDFEChannel implements org.drools.runtime.Channel {
@Override
public void send(Object o) {
System.err.println("Recieved channel message: " + o);
}
}
public class Average {
public static void main(String[] args) throws InterruptedException, IOException {
KnowledgeBaseConfiguration kbconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbconfig.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbconfig);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("drools53fusioneval/basic.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.err.println(kbuilder.getErrors().toString());
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
final StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
session.registerChannel("heartbeat", new AvgDFEChannel());
WorkingMemoryEntryPoint ep01 = session.getWorkingMemoryEntryPoint("ep01");
new Thread() {
public void run() {
session.fireUntilHalt();
}
}.start();
Thread.sleep(5000); // give the engine time to get setup
Server hiwaesdk = new Server("hiwaesdk");
session.insert(hiwaesdk);
long LIMIT = 10000;
long sentCount = 0;
int batchSize = 10000;
Random rnd = new Random(System.nanoTime());
int temp = 0;
long startTS = System.nanoTime();
while (sentCount < LIMIT) {
for (int i = 0; i < batchSize; i++) {
temp = rnd.nextInt(212);
IntEvent evt = new IntEvent (temp);
ep01.insert(evt);
sentCount++;
}
Thread.sleep (0x1);
}
double duration = (System.nanoTime() - startTS)/1000000.0;
System.out.println(LIMIT +" events generated in "+ duration +" milliseconds");
System.out.println("Last temperature submitted: "+ temp);
for (int i = 0; i < 5; i++) {
System.out.println ("Sec "+ i +": "+ hiwaesdk.currentTemp +", "+ hiwaesdk.readingCount);
Thread.sleep (1000);
}
System.exit(0);
}
}
### basic.drl ###
package drools53fusioneval
declare IntEvent
@role ( event )
end
rule "number rule"
when
$e : IntEvent () from entry-point ep01
$s : Server (hostname == "hiwaesdk")
then
$s.currentTemp = $e.data;
$s.readingCount++;
end