[rules-users] strategy for rulebase updates in a cluster?

psentosa psentosa at yahoo.com
Fri Aug 22 06:24:08 EDT 2008



having read your interesting discussion, I'd like to ask some additional
questions regarding using DROOLS in JEE environment. Actually JEE is also
quite new for me as well, so please give some corrections/ideas if I
misunderstand something.
Following problem:
I have some service implementation in my webapp for calculating/processing
inputs from user (I'll call these calculating/processing service). 
I try to integrate drools to do some checking on user input, before it is
saved into the DB and to generate some reports based on already saved data
respectively. 
For the integration purpose, I'd like to implement several additional
services for the rule-checking purpose (I'll call this checking-service),
each of which uses RuleAgent to create RuleBase from BRMS. The reason why I
need several services is because I separate my rules in different packages,
depending on which calculating/processing service to use the checking
service.

1st question here: is this the right strategy to separate the rule-checking
into some parts?

Now, for the checking itself, I use StatelessSession (The (checking)service
class for this is also a stateless session bean). Every time
calculation/processing service is called from the UI, it calls the checking
service, the checking service will do its parts with the Rule Engine, gets
result, and pass it back to the calculating/processing service.

2nd question: could such nested calls of services affect the performance of
the webapp (especially bcs it has to make additional call to BRMS for
creating the RuleAgent)

In the .properties file, I put the following options:
newInstance=true
poll=30
....
So, what I got on the console are the following messages, everytime my
checking service is contacted:
11:32:18,484 ERROR [STDERR] RuleAgent(ruleconfig) INFO (Fri Aug 22 11:32:18
CEST 2008): Applying changes to the rulebase.
11:32:18,484 ERROR [STDERR] RuleAgent(ruleconfig) INFO (Fri Aug 22 11:32:18
CEST 2008): Creating a new rulebase as per settings.
11:32:18,484 ERROR [STDERR] RuleAgent(ruleconfig) INFO (Fri Aug 22 11:32:18
CEST 2008): Adding package called mypackage1

The questions:
- Rules should be updateable, but less regularly (several times / year). I
set newInstance=true so that the webapp always gets the most updated rules,
but seeing that everytime calls are made, new rulebase is created as well,
I'm worried that there will be too many ressources in use. Or am I wrong? Is
there any alternative how to do this more efficiently?
- what is actually "poll" for? If I already get a fresh ruleagent for every
call, do I still need this one?

The webapp is still in testing phase, but later it could be used in a
cluster as well. Is BRMS also suitable in cluster-environment? Or is there
any limitation for the purpose?

Many thanks for any idea/critics/suggestions/tips, etc. Really appreciate
any response!

Regards




Edson Tirelli-3 wrote:
> 
>    Marina,
> 
>    Yes, stateless sessions have a reference to the rulebase, so that they
> can execute, but they automatically release all resources after executing.
> The difference to stateful sessions is that you must call dispose()
> manually
> for stateful sessions to release their resources. So you are fine.
> 
>    []s
>    Edson
> 
> 2008/8/20 Marina <ppine7 at yahoo.com>
> 
>> Edson,
>> Thanks for the quick reply.
>> I'll go for the approach #1. I am also thinking of using Stateless
>> sessions
>> rather than Stateful to basically always ensure that the engine does one
>> full run over a static set of rules. I am not going to maintain
>> long-running
>> sessions at all.
>>
>> One small question: when I create a StatelessSession from the rulebase,
>> will it also maintain a reference to the rulebase? In which case, when
>> the
>> session is done, is it going to release the reference? I'm trying to see
>> if
>> I am going to have some dangling references to old rulebases (R1)  laying
>> around even after the ruleBase variable in the singleton class points to
>> the
>> new R2 rulebase instance already. Just to make sure that old references
>> are
>> GC-ed properly, since, as I understand, rulebases are pretty big objects.
>>
>> Thanks,
>> Marina
>>
>>
>> ----- Original Message ----
>> From: Edson Tirelli <tirelli at post.com>
>> To: Rules Users List <rules-users at lists.jboss.org>
>> Sent: Wednesday, August 20, 2008 1:55:15 PM
>> Subject: Re: [rules-users] strategy for rulebase updates in a cluster?
>>
>>
>>    Marina,
>>
>>    Operations over an existing rulebase (add/remove rules/packages) will
>> lock existing stateful sessions in order to be executed making them
>> thread
>> safe. But having said that, for a JEE environment I would design it as in
>> scenario #1.
>>
>>    I.e., requests are arriving and being handled by sessions created
>> against a rulebase R1. When an update is made, the application will
>> simply
>> create a new rulebase (R2) and your singleton will now reference R2.
>> Working
>> memories have an internal reference to the rulebase used to create them,
>> so
>> existing sessions will work with the old rulebase until disposed, but any
>> new request will create sessions against R2 (since your singleton now
>> holds
>> a reference for R2).
>>
>>    I like this solution because it provides, IMO, the safest and more
>> consistent way of handling existing sessions, since you ensure a complete
>> reasoning cycle (session) is made with an immutable set of rules, that
>> can
>> be easily tracked by whatever audit mechanisms you use. Only new requests
>> will use the new rulebase, and are ensured to also complete the reasoning
>> with immutable rules.
>>
>>    If you have long running sessions, though, the problem is a bit
>> different and there is no other option IMO, except using solution #2.
>>
>>    Hope it helps,
>>       Edson
>>
>> 2008/8/20 Marina <ppine7 at yahoo.com>
>>
>>> Hello,
>>> I'm integrating DRools into a J2EE application and need to understand
>>> how
>>> it behaves in a multi-threaded distributed environment. I have many
>>> questions about thread safety but for now I'll ask about clustering only
>>> and
>>> post other questions separately.
>>>
>>> So, as I understand, Drools per se is not cluster-aware. In my current
>>> design I have a singleton class, RuleEngineMAnager, that holds a
>>> reference
>>> to a RuleBase. Hence, there will be one instance of a rulebase per JVM
>>> per
>>> machine in a cluster. Rules can be added/modified from any node in the
>>> cluster, and the modifications have to me made visible in all rulebases.
>>> The way I handle it now is by using a DB as the shared unit and setting
>>> up
>>> a flag when modifications are made in any JVM. Next time a request comes
>>> in
>>> for the rule engine to run all rule , the flag is checked and the
>>> RuleBase
>>> is updated.
>>>
>>> So, my question is about how to handle the rulebase updates most
>>> efficiently.
>>> I see two possibilities:
>>> 1. ditch the rulebase completely, build a new Package of rules , create
>>> a
>>> new rulebase and add the package to it
>>>
>>> 2. Use the same rulebase - just remove the old package of rules and load
>>> in the new one.
>>>
>>> The issues here are:
>>> -- what if there are operations going on in the rule engine, invoked
>>> from
>>> other threads, at the time I want to do either 1 or 2?
>>>
>>> Say, in the scenario #2, the rule engine is running all rules in one
>>>  thread. At the same time I'm asking it to drop the rule package from
>>> another thread and add the new one. Is it going to finish running all
>>> rules
>>> with the old package, return results, and only then do the update of the
>>> package?
>>>
>>> And in the scenario #1, if the rule engine is running the rules, and I
>>> try
>>> to destroy the old rule base - are those operations sequential?
>>>
>>> Any suggestions as to how to design this functionality in the most
>>> efficient and safe way?
>>>
>>> thank you!
>>> Marina Popova
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>
>>
>>
>> --
>> Edson Tirelli
>> JBoss Drools Core Development
>> JBoss, a division of Red Hat @ www.jboss.com
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
> 
> 
> -- 
> Edson Tirelli
> JBoss Drools Core Development
> JBoss, a division of Red Hat @ www.jboss.com
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/strategy-for-rulebase-updates-in-a-cluster--tp19072451p19104770.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list