[rules-users] Issue with parallel StatelessKnowledgeSession

Marc Mährländer maehrlaender at sifena.com
Tue Mar 26 10:27:55 EDT 2013


Hi,

I just tested the performance of Drools Expert for a scenario with a
number of Knowledbases most of them in sequential mode. I experienced
a strange behaviour when executing separated
StatelessKnowledgeSessions in parallel within different threads. In my
testcase, a queue is filled with 20 work items, each containing
indentical data objects approx. 10.000 objects. Consumers are taking
the work items from the queue and executing twelve
StatelessKnowledgeSessions with that input data in a row. The
Knowledgebases for each Thread are created independently. So the
different Threads do not share the same KnowledgeBase (but the
knowledge is created from the same drl files) nor do they share the
same input objects. (but the objects are created from one template as
deep copies).

I'm running on windows with a quad intel i7 cpu. When performing the
test with only one Thread, I need around 31s to empty the queue. When
starting the test with two consumer Threads I would expect the queue
to be emptied within nearly half of the time. But instead, it takes
28s, so only saving 2 seconds. So I start the same test in two
separated processes (virtual machines). I then get a calculated time
of around 17 second to process the 20 work items. So this is more or
less what I would expect.

I have the feeling, that there is some kind of synchronization between
two StatelessKnowledgeSessions, even if they are created independently
from each other. Observing the processes with VirtualVM in sample mode
shows method DefaultAgenda.notifyHalt() on top. That method is
synchronized, but on a local member which should normally not be a
problem

I'm using Drools Version 5.5.0 Final with Oracle JDK 7. There are
several hundert rules within the .drl files. Consumer threads are
created like this:

for (int i=0;i<consumerCount;i++)
		{
			GroupConsumer consumer = new
GroupConsumer((List<KnowledgeBase>)deepCopy(buildKnowledge()),queue,
"Consumer"+i);
			consumers.add(consumer);
			
		}

This is the code to execute the Sessions (Sessions are currently
cached within implementation of the consumers, but creating new
session for every work item does not change behaviour)

for (StatelessKnowledgeSession ksession : sessions)
		{
			
			long t1 = System.nanoTime();
			
			ksession.setGlobal("annual_sales", 200000.0);
			ksession.setGlobal("annual_assets", 10000000.0);
			ksession.setGlobal("FLAG_31_4_INSTITUTE",1);
			ksession.setGlobal("RW_INTRA_GROUP", 0.5);
			ksession.setGlobal("REPDATE", repdate);
			ksession.setGlobal("T3M", t3m);
			ksession.setGlobal("T1M", t1m);
			ksession.setGlobal("T2W", t2w);
			ksession.setGlobal("T6M",t6m);
			ksession.setGlobal("T12M", t12m);
			ksession.setGlobal("T24M", t24m);
			ksession.setGlobal("T60M", t60m);
			ksession.setGlobal("DEFAULT_FSA_B825", defaultRating);
			ksession.setGlobal("jcalF001","10-xxx-x-xx-xxxx");
			ksession.setGlobal("NEW_OBJS", newObjs);
			ksession.execute(group);
			totalDroolsTime = totalDroolsTime + System.nanoTime() - t1;
			
			group.addAll(newObjs);
			newObjs.clear();
			
		}

Is there anything I may have made wrong?

Regards,

-- 

Marc Mährländer
------------------------------------------------------------------------------------------------------------------------
Sifena Ltd - Dalkeith - Nursery Close - Woking - GU21 4UQ United Kingdom

email:      marc.maehrlaender at sifena.com

tel:        +49 (89) 420 957 312

mobile:   +49 (177) 766 2008



More information about the rules-users mailing list