Hi!
Just the answer I was hoping for, thanks for the fast reply!
/Mikael
Mark Proctor wrote:
Mikael Larsson wrote:
> Hi!
>
> I have some questions about multithreaded apps and if it is necessary
> to pool session objects for performance.
You don't need to pool session in drools, just cache the rulebase in a
singleton.
>
> * I understand that it is expensive to create the RuleBase objects
> but what about the sessions?
> If I create a new stateful session object for each request will that
> become a potential bottleneck?
sessions are lightweight, do not pool.
>
> * Is the session class thread safe, what will happen if two or more
> threads simultaneously call fireAllRules on one and the same session
> object?
sessions are thread safe, apart from the iterators.
>
> One advantage of pooling session is if you have some data that does
> not change per request. Say that I have some data associated with a
> specific type of request that should be inserted for all requests of
> that particular type and evaluated towards request specific stuff,
> e.g. params in the request. E.g. An object that specifies allowed
> values for a particular API will be the same for all requests (well
> at least until you reconfigure the allowed values...) and the rules
> would evaluate the request specific value based on the "allowed
> values" object. In this case only the request specific
> parameter/value needs to be inserted/retracted per request.
>
> * I would rather use StatefulSession instead of stateless since I
> find the API more flexible, are there any performance considerations
> I should be aware of? If pooling is necessary I guess I must use the
> stateful session. But if creating one session per request, are there
> any concrete reasons for using the stateless session (besides the
> simpler API and that I need to call dispose on the stateful session)?
stateless just wraps stateful anyway, stateless is really just a
convienience api - how stateless sessions do allow for "sequential
rete" which is a performance improvement if you don't need information
(fact modications leading to rule re-evaluation) but you have to go to
large number of rules and objects to see a big difference with
sequential rete.
>
> Kind of hoping that the answer will be: "No, pooling will not be
> necessary.", but any feedback about situations where it may be
> necessary for best performance would be much appreciated.
No, pooling will not be neceesary.
>
> Regards,
> /Mikael
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
______________________________________________
Mikael Larsson
Redpill AB
Tel. + 46 54 15 09 40
Mob. + 46 73 42 41 483