Group,
The following HelloWorld example is taken from the example code coming with the latest
Drools downloads. One modification is the addition of the loop(10K times). Please note
that the loading of the drl file is outside of this loop. Our developer tells us that
this same example runs in 300milliseconds in Drools 2.0. Version 5.0 runs for 10
seconds. We have a large batch process that will suffer greatly if this is something we
can't work around. Any ideas for performance gains in 5.0 will be greatly
appreciated.
Duane
duane(a)proqualitysoft.com
public static final void main(final String[] args) throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
HelloWorldExample.class), ResourceType.DRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile
\"HelloWorld.drl\".");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.setGlobal("list", new ArrayList<Object>());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "log/helloworld");
long starttime = System.currentTimeMillis();
for(int u=0;u<10000;u++)
{
final Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
}
long endtime = System.currentTimeMillis();
System.out.println("execution time is "+(endtime-starttime));
logger.close();
ksession.dispose();
}