Thanks for the link :) 'Twas an interesting view! A few complexities still
remain. I may be ill-informed about this matter so please correct me if I'm
totally off-base in any of these statements.
Alexandre states that the KnowledgeSession is thread safe, which is contrary
to the documentation (if he is is referring to a StatefulKnowledgeSession).
However, it seems like he is actually using a StatelessKnowledgeSession
pulling his facts from Redis. Our requirements are different, we are dealing
with real-time data, not historical data, and this real-time data will all
be stored in a long-running StatefulKnowledgeSession. So every fact in that
StatefulKnowledgeSession will be an active real-time representation of an
object's state. However, we do share a similar approach in that we are also
"going async" using queues. The reasoning for choosing the queue for us is
based on a variety of considerations, the most relevant for this
conversation is the fact that, based on the un-thread-safe nature of the
StatefulKnowledgeSession, we anticipate processing one record at a time (one
call to fireAllRules() per event). Does this seem like a reasonable
approach?
I have considered inserting multiple events (as facts) per call to
FireAllRules(), but am uncertain of how the conflict resolution should work
if say for instance two of those facts correspond to the same field of the
same object. Here's a pseudo-code example outlining my concern:
Key assumption: It is NOT possible to concurrently access a
StatefulKnowledgeSession from multiple threads or separate parallel REST
service calls.
//Assume KnowledgeBase has already been built and sks is our long-running
global singleton //StatefulKnowledgeSession which has continuity between
individual REST web-service sessions.
//Begin Pseudo-Code Snippet.
//objectA with Data Member "Integer A" Value 1
sks.insert(objectA);
sks.insert(objectB);
sks.insert(objectC);
//objectA with Data Member "Integer A" Value 2 (this is an update to the
same object which has a higher //index in the chronologically sorted queue).
sks.insert(objectA);
sks.fireAllRules();
//End Pseudo-Code Snippet.
As you can see, we enter multiple facts into the session for a single call
to FireAllRules(), and objectA contains a conflict because there are two
separate events relating to an update to the same object (objectA) and the
same field (integerA).
Does this seem like a reasonable or feasible approach? What would happen in
this scenario? Should we just try to work around it by pre-determining such
conflicts?
Which of the two is advised? Single Event per SKS fireAllRules() call or
Multiple Events per fireAllRules() call? Again, performance is important,
but we must temper such desires with our considerations of data-integrity :)
I REALLY REALLY Appreciate the help you've provided thus far.
Thanks for all the shoes,
Lucas (Skiddlebop)
--
View this message in context:
http://drools.46999.n3.nabble.com/StatefulKnowledgeSession-and-multi-thre...
Sent from the Drools: User forum mailing list archive at
Nabble.com.