Mark Proctor | 1 Aug 19:24

[rules-dev] Re: [rules-users] determinism with rulebase partitioning

Sorry I meant to ask this on th dev list :(
Anstis, Michael (M.) wrote:
> Hi Mark,
>
> A few questions:-
>
> (A) What does "parallel evaluation of a rulebase" mean? Is it designed
> to optimise, for example, two threads processing a stateless and
> stateful session?
>   
It works out the parts of the network that can be isolated, so we can 
use multiple threads in parallel for evalation of a rulebase.
> (B) Are there only two partitions, both of which are invisible to the
> user? Is there any value in allowing user-defined partitions?
>   
There could be any number of partitions depending on the analysis of the 
rulebase. It's an internal optimisation of a rulebase, so it's not 
something they are aware of. A user cannot define a partition, as 
partitions are determined by the rules written and their level of isolation.
> (C) Does the partition used depend upon what type of session is used
> (i.e. stateless always uses the partition without an agenda whereas
> stateful always uses the partition with an agenda)?
>   
it analysesthe rulebase, nothing to do with the session type. However 
stateless sessions without inference typically don't need determinstic 
execution, so we can just evaluate and fire there.
> (D) Can a rule sometimes be deterministic and sometimes not (i.e.
> depends upon the type of session)?
>   
Not on the type of session, no. And having a rule sometimes determinstic 
(Continue reading)

Mark Proctor | 1 Aug 19:27

[rules-dev] [Fwd: Re: [rules-users] determinism with rulebase partitioning]

Forwarding the email to the dev mailing list, I meant the conversation to be on this list anyway - sorry.

mark

-------- Original Message --------


    I think that even with rulebase partitions, we should continue to support current execution mode. So, we should keep a rulebase configuration that basically allow the user to defines: either single-thread (as it is today) or multi-thread (as we are trying to achieve) execution.

    Having that in mind, in the multi-thread mode:

(A) What does "parallel evaluation of a rulebase" mean? Is it designed
to optimise, for example, two threads processing a stateless and
stateful session?
   Means that rules that do not share nodes, being independent of each other (from an evaluation perspective), will be evaluated in parallel. This is very common scenario and a desidered feature in CEP engines.

(B) Are there only two partitions, both of which are invisible to the
user? Is there any value in allowing user-defined partitions?
    There will be as many partitions as the compiler can create for the given set of rules. Rules that share more nodes, are more difficult to partition, while rules that are independent from an LHS point of view, are easier to parallelize. In my opinion, the only thing that may be helpful to expose and allow the user to control is the maximum size of the thread pool that is used to propagate facts. Even that I'm not sure is so helpful, because it is complex to fine tune such things, since the partitioning is completely dependent on the rules added to the rulebase.

(C) Does the partition used depend upon what type of session is used
(i.e. stateless always uses the partition without an agenda whereas
stateful always uses the partition with an agenda)?
    The partitioning of the rulebase is dependent upon the rules in the rulebase and nothing more. But that is different from the agenda. The agenda issue is much more complex, because even with partitions we can keep a single deterministic agenda (as long as it is not in active mode - runUntilHalt). Now, if the agenda is in active mode, or if we have multiple agendas (1 per partition, for instance), then the engine behavior becomes indeterministic. This is a common scenario in CEP systems that have multiple different "queries" running over the same set of streams, trying to detect and act upon them as soon as they are detected, and event streams are indeterministic by their own nature. In common rules engines scenarios, I'm not sure we can run in this indeterministic mode.

(D) Can a rule sometimes be deterministic and sometimes not (i.e.
depends upon the type of session)?
    It will always depend on the set of rules (the rulebase), not the type of session. One rule is always deterministic when considered in isolation, but two or more rules may or may not be deterministic in relation to each other. Just remember Eisten's Relativity Theory... ;)

   []s
   Edson

2008/8/1 Anstis, Michael (M.) <manstis1 <at> ford.com>
Hi Mark,

A few questions:-

(A) What does "parallel evaluation of a rulebase" mean? Is it designed
to optimise, for example, two threads processing a stateless and
stateful session?

(B) Are there only two partitions, both of which are invisible to the
user? Is there any value in allowing user-defined partitions?

(C) Does the partition used depend upon what type of session is used
(i.e. stateless always uses the partition without an agenda whereas
stateful always uses the partition with an agenda)?

(D) Can a rule sometimes be deterministic and sometimes not (i.e.
depends upon the type of session)?

Cheers,

Mike

-----Original Message-----
From: rules-users-bounces <at> lists.jboss.org
[mailto:rules-users-bounces <at> lists.jboss.org] On Behalf Of Mark Proctor
Sent: 01 August 2008 07:05
To: Rules Users List
Subject: [rules-users] determinism with rulebase partitioning

We have rulebase partitioning almost working, this allows parallel
evaluation of a rulebase. For stateless lessions with no agenda this
will allow for much faster executions, where you don't care about
deterministic execution. However for deterministic execution its more
complicated. The current plan is to have an agenda per parition, which
means that we no longer have rulebase wide deterministic execution
order, only with the partition itself. The user is unlikely to be aware
of the created partitions, so won't be aware of the unditermistic
behavour of their rulebase. Anyone have any input on mechanisms users
can do to help the rulebase know what needs to be executed
deterministically and what doesn't?

Mark
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
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 <at> www.jboss.com
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev
Picon
Favicon

RE: [rules-dev] [Fwd: Re: [rules-users] determinism with rulebasepartitioning]

All very interesting.
 
Sadly, without spending time I don't have, this is beyond my level of understanding.
 
Sometimes you have to be honest and admit you're out of your depth, so I'll leave this with the experts...
 
Relative to this observer you're moving at one heck of a pace!
 
Thanks for the reply though.
 
Mike 

From: rules-dev-bounces <at> lists.jboss.org [mailto:rules-dev-bounces <at> lists.jboss.org] On Behalf Of Mark Proctor
Sent: 01 August 2008 18:28
To: Rules Dev List
Subject: [rules-dev] [Fwd: Re: [rules-users] determinism with rulebasepartitioning]

Forwarding the email to the dev mailing list, I meant the conversation to be on this list anyway - sorry.

mark

-------- Original Message --------


    I think that even with rulebase partitions, we should continue to support current execution mode. So, we should keep a rulebase configuration that basically allow the user to defines: either single-thread (as it is today) or multi-thread (as we are trying to achieve) execution.

    Having that in mind, in the multi-thread mode:

(A) What does "parallel evaluation of a rulebase" mean? Is it designed
to optimise, for example, two threads processing a stateless and
stateful session?
   Means that rules that do not share nodes, being independent of each other (from an evaluation perspective), will be evaluated in parallel. This is very common scenario and a desidered feature in CEP engines.

(B) Are there only two partitions, both of which are invisible to the
user? Is there any value in allowing user-defined partitions?
    There will be as many partitions as the compiler can create for the given set of rules. Rules that share more nodes, are more difficult to partition, while rules that are independent from an LHS point of view, are easier to parallelize. In my opinion, the only thing that may be helpful to expose and allow the user to control is the maximum size of the thread pool that is used to propagate facts. Even that I'm not sure is so helpful, because it is complex to fine tune such things, since the partitioning is completely dependent on the rules added to the rulebase.

(C) Does the partition used depend upon what type of session is used
(i.e. stateless always uses the partition without an agenda whereas
stateful always uses the partition with an agenda)?
    The partitioning of the rulebase is dependent upon the rules in the rulebase and nothing more. But that is different from the agenda. The agenda issue is much more complex, because even with partitions we can keep a single deterministic agenda (as long as it is not in active mode - runUntilHalt). Now, if the agenda is in active mode, or if we have multiple agendas (1 per partition, for instance), then the engine behavior becomes indeterministic. This is a common scenario in CEP systems that have multiple different "queries" running over the same set of streams, trying to detect and act upon them as soon as they are detected, and event streams are indeterministic by their own nature. In common rules engines scenarios, I'm not sure we can run in this indeterministic mode.

(D) Can a rule sometimes be deterministic and sometimes not (i.e.
depends upon the type of session)?
    It will always depend on the set of rules (the rulebase), not the type of session. One rule is always deterministic when considered in isolation, but two or more rules may or may not be deterministic in relation to each other. Just remember Eisten's Relativity Theory... ;)

   []s
   Edson

2008/8/1 Anstis, Michael (M.) <manstis1 <at> ford.com>
Hi Mark,

A few questions:-

(A) What does "parallel evaluation of a rulebase" mean? Is it designed
to optimise, for example, two threads processing a stateless and
stateful session?

(B) Are there only two partitions, both of which are invisible to the
user? Is there any value in allowing user-defined partitions?

(C) Does the partition used depend upon what type of session is used
(i.e. stateless always uses the partition without an agenda whereas
stateful always uses the partition with an agenda)?

(D) Can a rule sometimes be deterministic and sometimes not (i.e.
depends upon the type of session)?

Cheers,

Mike

-----Original Message-----
From: rules-users-bounces <at> lists.jboss.org
[mailto:rules-users-bounces <at> lists.jboss.org] On Behalf Of Mark Proctor
Sent: 01 August 2008 07:05
To: Rules Users List
Subject: [rules-users] determinism with rulebase partitioning

We have rulebase partitioning almost working, this allows parallel
evaluation of a rulebase. For stateless lessions with no agenda this
will allow for much faster executions, where you don't care about
deterministic execution. However for deterministic execution its more
complicated. The current plan is to have an agenda per parition, which
means that we no longer have rulebase wide deterministic execution
order, only with the partition itself. The user is unlikely to be aware
of the created partitions, so won't be aware of the unditermistic
behavour of their rulebase. Anyone have any input on mechanisms users
can do to help the rulebase know what needs to be executed
deterministically and what doesn't?

Mark
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
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 <at> www.jboss.com
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev
Michael Neale | 6 Aug 09:10
Picon
Gravatar

Re: [rules-dev] Rule Parameters/Aliases

One thing that people missed that may be interesting is the fact aliasing.

So in the simplest case this is simply renaming a fact so instead of:

FooBar() in a rule, you could write YourFabulousObject(). That is clear enough.

What would be interesting is the following:

FooBar(someField == "abc") aliased too SomethingElse()

so the someField == "abc" constraint is always implicitly applied.

I could see this being useful, especially when generic facts are
used.. this could be

Thoughts - any one wanna have a crack at implementing this?

On Sat, Jul 19, 2008 at 3:31 AM, Mark Proctor <mproctor <at> codehaus.org> wrote:
> Found this:
> http://www.ilog.com/products/jrules/documentation/jrules67/rtsohelp/wbg_config7.html
> "A ruleset parameter is the equivalent of a global variable"
>
> So a ruleset parameter is nothing more than a global, so just use our
> globals as is and you get IN_OUT capabilities. I would strongly advise you
> against representing your entire model this way and just using evals.
>
> Mark
>
>
> Mark Proctor wrote:
>
> Yoni Mazar wrote:
>
> Hi all,
> We are at the begining of a new clinical decision-support project. We plan
> using drools (using Eclipse) in order to manage and execute our
> business logic. As part of our research, we also evaluated JRules which has
> a feature that
> is very important to us and we could not find in Drools.
>
> I've reference the ilog manual on in/out parameters if anyone doesn't know
> what they are:
> http://www.ilog.com/products/jrules/documentation/jrules67/rsruleset/rs_rls_parameters.html#1026848
> http://www.ilog.com/products/jrules/documentation/jrules67/rsruleset/rs_rls_tskcreatingrulesetparams.html
>
> I don't see the difference between a global and an IN_OUT parameter, and I
> don't see the value of specifically saying which parameters are IN and which
> are OUT. It doesn't seem that parameters are facts, they are not asserted
> into the engine and propagated through the working memory - atleaast I don't
> think they are, the manual doesn't say clearly enough, it just says they can
> be referenced from any ruleset component, which seems to be akin to how we
> do globals.
>
> Unless we missed it out, we will probably try and add this functionality
> ourselves.
>
> In JRules, one can define a ruleset (corresponds to a package) with
> parameters. Each parameter has a datatype (a class), a direction
> (in/out/inout), and an alias. Then, within the rules, the user can refer to
> the parameter alias. For
> example, a user can define a ruleset with the following parameters:
> *class=LabResult, direction=in, alias=hemoglobin *class=LabResult,
> direction=in, alias=creatinin
> Then, within a rule, one can write: when hemoglobin.value<10 and
> creatinin.value>34 then...
>
> We can do the same with globals, but what that actually means is you have a
> rule that doesn't use any working memory objects, and you put the
> constraints into one big eval - no pattern matching, so you are turning the
> rule engine into a scripting engine rather than a production rule system.
>
> If they are indeed facts that allow for pattern matching, then it seems that
> they constraint by the variable name rather than by object type. I've never
> liked this, again why not just use mvel directly as a scripting engine. But
> I have thought of how this would be possible, somethign I call Named Facts -
> where asserted facts can be given a unique string identifier and a pattern
> can be told to not only constraint against that object type, but also
> against that variable name. However this is something that users can emulate
> themselves now, by just putting an "identifier" field on their facts and
> constraining on it in the pattern. If someone comes up with a clean way for
> supporting named facts and provides a patch we will consider including it,
> but it's not one of our priorities at the moment.
>
>
> Now, the application retrieves the patient data accordingly (hemoglobin and
> creatinine data separetly - even though they are of the same type) and sets
> the ruleset parameters: ruleset.parameters.add("hemoglobin",hemoglobinFact)
> ruleset.parameters.add("creatinin",creatininFact)
> It is important that the definition of the aliases will be done outside of
> the rule (and not by defining in-rule variables)
>
> This approach simplifies the rules since some of the filtering is being
> applied externally (not in the rule itself)
>
>
> sounds like it simplifies it, by turning it into a scripting engine where
> all facts are variables with identifiers.
>
> Does someone has an idea how to bridge this gap using Drools? Are there any
> workarounds that can be used in order to avoid changes in
> code?
>
>
> Hopefully my main paragraph above shows you how to emulate this.
>
> And here we can use your help:
> We are new to Drools (and still have to dive into the big ocean of code that
> exists). The following features
>
> 1) defining parameters (in the package level...something like import)
> 2) adding in/out modifiers (can be used in LHS, RHS, or both)
> 3) allowing assignment of aliases to parameters 4) adding such functionality
> to the rule editor (auto-complete ,type safety)
>
> Where should we start?
> Do you have any ideas that can help start this process (e.g. relevant
> classes, modules)?
> We would appreciate any help regarding any of the items in the list above.
> Any hints, suggestions, directions, referals and so on.
>
>
> IF IN_OUT params are nothign more than globals and big fat evails, then you
> have nothing to do.
>
> If they are named facts, it won't be easy, but you could try the following
> approach:
> 1) update drools to support named facts, as described previously, this will
> involve a special type of ObjectType I imagine, and you'll have to change
> how it matches ObjectTypes so that it also has access to the possible
> variable name.
> 2) figure out a sane syntax, that is not ambigious, to allow pattern
> matching on named facts, and update our Antlr files to support this.
> 4) I don't konw if in/out parameters are useful for a stateful session, or
> only stateless. Either way you will probably want to create some Context
> object that contains these parameters and then you "insert" them using
> smething like insertWithParameters( myParams ). With stateless it'll execute
> and return results directly, with stateful you'll have to figure out how
> that'll work with possible incremental inserts and fireallrules being called
> separately.
> 4) Write lots of tests ot make sure it doesn't break anything
>
> Thanks a lot.
>
> Yoni
>
>
>
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev <at> lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
>

--

-- 
Michael D Neale
home: www.michaelneale.net
blog: michaelneale.blogspot.com
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

Michal Bali | 6 Aug 09:53
Picon
Gravatar

Re: [rules-dev] Rule Parameters/Aliases

Hi, nice idea,

Yoni, in your case the aliases could be implemented as immutable wrapper objects, that implement the same interfaces and just delegate to the wrapped object (alternatively they could extend the object, however the rules will need to do instanceof checking to avoid recursion)

example:
rule aliasRule
    when
        $diagnosis : Diagnosis(alias == "anemia")
    then
        insert(new DiagnosisAnemia($diagnosis));
end

rule businessRule
    when
        DiagnosisAnemia(code == "5")
    then
        //do something
end

The wrapper object should be immutable, otherwise when doing updates you'll have to update both, alias and the original object.

You could have 2 rule packages - one for setting up aliases and one for business logic, so that it will be separated

I hope this helps.
Regards,
Michal


On Wed, Aug 6, 2008 at 8:10 AM, Michael Neale <michael.neale <at> gmail.com> wrote:
One thing that people missed that may be interesting is the fact aliasing.

So in the simplest case this is simply renaming a fact so instead of:

FooBar() in a rule, you could write YourFabulousObject(). That is clear enough.

What would be interesting is the following:

FooBar(someField == "abc") aliased too SomethingElse()

so the someField == "abc" constraint is always implicitly applied.

I could see this being useful, especially when generic facts are
used.. this could be

Thoughts - any one wanna have a crack at implementing this?

On Sat, Jul 19, 2008 at 3:31 AM, Mark Proctor <mproctor <at> codehaus.org> wrote:
> Found this:
> http://www.ilog.com/products/jrules/documentation/jrules67/rtsohelp/wbg_config7.html
> "A ruleset parameter is the equivalent of a global variable"
>
> So a ruleset parameter is nothing more than a global, so just use our
> globals as is and you get IN_OUT capabilities. I would strongly advise you
> against representing your entire model this way and just using evals.
>
> Mark
>
>
> Mark Proctor wrote:
>
> Yoni Mazar wrote:
>
> Hi all,
> We are at the begining of a new clinical decision-support project. We plan
> using drools (using Eclipse) in order to manage and execute our
> business logic. As part of our research, we also evaluated JRules which has
> a feature that
> is very important to us and we could not find in Drools.
>
> I've reference the ilog manual on in/out parameters if anyone doesn't know
> what they are:
> http://www.ilog.com/products/jrules/documentation/jrules67/rsruleset/rs_rls_parameters.html#1026848
> http://www.ilog.com/products/jrules/documentation/jrules67/rsruleset/rs_rls_tskcreatingrulesetparams.html
>
> I don't see the difference between a global and an IN_OUT parameter, and I
> don't see the value of specifically saying which parameters are IN and which
> are OUT. It doesn't seem that parameters are facts, they are not asserted
> into the engine and propagated through the working memory - atleaast I don't
> think they are, the manual doesn't say clearly enough, it just says they can
> be referenced from any ruleset component, which seems to be akin to how we
> do globals.
>
> Unless we missed it out, we will probably try and add this functionality
> ourselves.
>
> In JRules, one can define a ruleset (corresponds to a package) with
> parameters. Each parameter has a datatype (a class), a direction
> (in/out/inout), and an alias. Then, within the rules, the user can refer to
> the parameter alias. For
> example, a user can define a ruleset with the following parameters:
> *class=LabResult, direction=in, alias=hemoglobin *class=LabResult,
> direction=in, alias=creatinin
> Then, within a rule, one can write: when hemoglobin.value<10 and
> creatinin.value>34 then...
>
> We can do the same with globals, but what that actually means is you have a
> rule that doesn't use any working memory objects, and you put the
> constraints into one big eval - no pattern matching, so you are turning the
> rule engine into a scripting engine rather than a production rule system.
>
> If they are indeed facts that allow for pattern matching, then it seems that
> they constraint by the variable name rather than by object type. I've never
> liked this, again why not just use mvel directly as a scripting engine. But
> I have thought of how this would be possible, somethign I call Named Facts -
> where asserted facts can be given a unique string identifier and a pattern
> can be told to not only constraint against that object type, but also
> against that variable name. However this is something that users can emulate
> themselves now, by just putting an "identifier" field on their facts and
> constraining on it in the pattern. If someone comes up with a clean way for
> supporting named facts and provides a patch we will consider including it,
> but it's not one of our priorities at the moment.
>
>
> Now, the application retrieves the patient data accordingly (hemoglobin and
> creatinine data separetly - even though they are of the same type) and sets
> the ruleset parameters: ruleset.parameters.add("hemoglobin",hemoglobinFact)
> ruleset.parameters.add("creatinin",creatininFact)
> It is important that the definition of the aliases will be done outside of
> the rule (and not by defining in-rule variables)
>
> This approach simplifies the rules since some of the filtering is being
> applied externally (not in the rule itself)
>
>
> sounds like it simplifies it, by turning it into a scripting engine where
> all facts are variables with identifiers.
>
> Does someone has an idea how to bridge this gap using Drools? Are there any
> workarounds that can be used in order to avoid changes in
> code?
>
>
> Hopefully my main paragraph above shows you how to emulate this.
>
> And here we can use your help:
> We are new to Drools (and still have to dive into the big ocean of code that
> exists). The following features
>
> 1) defining parameters (in the package level...something like import)
> 2) adding in/out modifiers (can be used in LHS, RHS, or both)
> 3) allowing assignment of aliases to parameters 4) adding such functionality
> to the rule editor (auto-complete ,type safety)
>
> Where should we start?
> Do you have any ideas that can help start this process (e.g. relevant
> classes, modules)?
> We would appreciate any help regarding any of the items in the list above.
> Any hints, suggestions, directions, referals and so on.
>
>
> IF IN_OUT params are nothign more than globals and big fat evails, then you
> have nothing to do.
>
> If they are named facts, it won't be easy, but you could try the following
> approach:
> 1) update drools to support named facts, as described previously, this will
> involve a special type of ObjectType I imagine, and you'll have to change
> how it matches ObjectTypes so that it also has access to the possible
> variable name.
> 2) figure out a sane syntax, that is not ambigious, to allow pattern
> matching on named facts, and update our Antlr files to support this.
> 4) I don't konw if in/out parameters are useful for a stateful session, or
> only stateless. Either way you will probably want to create some Context
> object that contains these parameters and then you "insert" them using
> smething like insertWithParameters( myParams ). With stateless it'll execute
> and return results directly, with stateful you'll have to figure out how
> that'll work with possible incremental inserts and fireallrules being called
> separately.
> 4) Write lots of tests ot make sure it doesn't break anything
>
> Thanks a lot.
>
> Yoni
>
>
>
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev <at> lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
>



--
Michael D Neale
home: www.michaelneale.net
blog: michaelneale.blogspot.com
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev
Harsh Jetly | 6 Aug 12:53
Favicon

Re: [rules-dev] Drools Stateful Session Thread Safe


ricky.nfs wrote:
> 
> Hi there, I am a newbie on Drools. I tried to create a multi threading
> programs using drools. But in large amount of threads, the result in
> stateful session is not safe anymore. Can anyone help me?
> 
> private final static Map<Integer,Double> score = new HashMap<Integer,
> Double>();
> 	
> 	static
> 	{
> 		score.put( 0 , 0.0 );
> 		score.put( 1 , 0.84 );
> 		score.put( 2 , 1.26 );
> 		score.put( 3 , 1.68 );
> 		score.put( 4 , 1.05 ); //Else
> 	}
> 
> 	public static void main(String[] args) throws Exception{
> 		
> 		Reader source = new InputStreamReader(
> TestStatefulSimpe.class.getResourceAsStream( "/simple/SimpleCATRule.dslr"
> ) );
> 		Reader dsl = new InputStreamReader(
> TestStatefulSimpe.class.getResourceAsStream( "/simple/SimpleCATRule.dsl" )
> );
> 		PackageBuilder builder = new PackageBuilder();
> 		builder.addPackageFromDrl( source, dsl );
> 		
> 		//get the compiled package (which is serializable)
> 		Package pkg = builder.getPackage();
> 		
> 		//add the package to a rulebase (deploy the rule package).
> 		org.drools.RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> 		ruleBase.addPackage( pkg );
> 		
> 		final StatefulSession statefulSession = ruleBase.newStatefulSession();
> 
> 		for( int i = 0 ; i < 200000 ; i++ )
> 		{
> 			final int idx = i;
> 			Thread t = new Thread( new Runnable(){
> 
> 				@Override
> 				public void run() {
> 					int amount = (int) Math.round( ( Math.random()*4 ) );
> 					TestSimpleVO vo = new TestSimpleVO();
> 					vo.setDecisionMakersAmount( amount );
> 					FactHandle fact = statefulSession.insert( vo );
> 					statefulSession.fireAllRules();
> 					statefulSession.retract(fact);
> 					if(  score.get(amount).doubleValue() != vo.getScoreFactor() )
> 						System.out.println( idx + " - " +  amount + " : " +
> score.get(amount).doubleValue() + " - " + vo.getScoreFactor() );
> 					statefulSession.dispose();
> 				}});
> 			t.start();
> 		}
> 	} 
> 
> And the dslr and dlr attachment : 
>  http://www.nabble.com/file/p18564976/SimpleCATRule.dsl SimpleCATRule.dsl 
>  http://www.nabble.com/file/p18564976/SimpleCATRule.dslr
> SimpleCATRule.dslr 
> 
> I really appreciate for any help or answer.
> 
> Thanks in advance,
> Ricky
> 

--

-- 
View this message in context: http://www.nabble.com/Drools-Stateful-Session-Thread-Safe-tp18564976p18848760.html
Sent from the drools - dev mailing list archive at Nabble.com.

_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

Harsh Jetly | 6 Aug 13:05
Favicon

[rules-dev] Problem while using RuleFlow Groups in drools


Hi ,
The version of Drools that I have used is 4.0.4

I have used ruleflow groups to create my rule file.
It has a split node (XOR) in which I specify a constraint on which a
ruleflow-group is to be selected .

Insert arraylists as facts in the working memory one by one.

The problem I face is that when I insert these arraylists in the same
session , it doesn't evaluate every constraint in the split node .

The work around I am using , it that I create a new session for every
arraylist , this works just fine . But creating a new session always is an
overhead .

Can you please assist me with this situation .

Thank You

Harsh Jetly 
--

-- 
View this message in context: http://www.nabble.com/Problem-while-using-RuleFlow-Groups-in-drools-tp18843391p18843391.html
Sent from the drools - dev mailing list archive at Nabble.com.

_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

Harsh Jetly | 6 Aug 13:38
Favicon

[rules-dev] Should I use drools for this application ?


--

-- 
View this message in context: http://www.nabble.com/Should-I-use-drools-for-this-application---tp18849397p18849397.html
Sent from the drools - dev mailing list archive at Nabble.com.

_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev

Edson Tirelli | 6 Aug 17:39

Re: [rules-dev] Drools Stateful Session Thread Safe


   A session never was thread safe... it is supposed to be accessed by a single thread.
   What *is* thread safe is a RuleBase, after its creation. So, if you change your code to have:

final StatefulSession statefulSession = ruleBase.newStatefulSession();

    Inside your thread, it should work.
    I.e., you share your rulebase, but creates a session for each thread, that seems precisely what you need, since your threads are (correctly) calling session.dispose().

   []s
   Edson

2008/8/6 Harsh Jetly <harsh.jetly <at> lntinfotech.com>



ricky.nfs wrote:
>
> Hi there, I am a newbie on Drools. I tried to create a multi threading
> programs using drools. But in large amount of threads, the result in
> stateful session is not safe anymore. Can anyone help me?
>
> private final static Map<Integer,Double> score = new HashMap<Integer,
> Double>();
>
>       static
>       {
>               score.put( 0 , 0.0 );
>               score.put( 1 , 0.84 );
>               score.put( 2 , 1.26 );
>               score.put( 3 , 1.68 );
>               score.put( 4 , 1.05 ); //Else
>       }
>
>       public static void main(String[] args) throws Exception{
>
>               Reader source = new InputStreamReader(
> TestStatefulSimpe.class.getResourceAsStream( "/simple/SimpleCATRule.dslr"
> ) );
>               Reader dsl = new InputStreamReader(
> TestStatefulSimpe.class.getResourceAsStream( "/simple/SimpleCATRule.dsl" )
> );
>               PackageBuilder builder = new PackageBuilder();
>               builder.addPackageFromDrl( source, dsl );
>
>               //get the compiled package (which is serializable)
>               Package pkg = builder.getPackage();
>
>               //add the package to a rulebase (deploy the rule package).
>               org.drools.RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>               ruleBase.addPackage( pkg );
>
>               final StatefulSession statefulSession = ruleBase.newStatefulSession();
>
>               for( int i = 0 ; i < 200000 ; i++ )
>               {
>                       final int idx = i;
>                       Thread t = new Thread( new Runnable(){
>
>                               <at> Override
>                               public void run() {
>                                       int amount = (int) Math.round( ( Math.random()*4 ) );
>                                       TestSimpleVO vo = new TestSimpleVO();
>                                       vo.setDecisionMakersAmount( amount );
>                                       FactHandle fact = statefulSession.insert( vo );
>                                       statefulSession.fireAllRules();
>                                       statefulSession.retract(fact);
>                                       if(  score.get(amount).doubleValue() != vo.getScoreFactor() )
>                                               System.out.println( idx + " - " +  amount + " : " +
> score.get(amount).doubleValue() + " - " + vo.getScoreFactor() );
>                                       statefulSession.dispose();
>                               }});
>                       t.start();
>               }
>       }
>
> And the dslr and dlr attachment :
>  http://www.nabble.com/file/p18564976/SimpleCATRule.dsl SimpleCATRule.dsl
>  http://www.nabble.com/file/p18564976/SimpleCATRule.dslr
> SimpleCATRule.dslr
>
> I really appreciate for any help or answer.
>
> Thanks in advance,
> Ricky
>

--
View this message in context: http://www.nabble.com/Drools-Stateful-Session-Thread-Safe-tp18564976p18848760.html
Sent from the drools - dev mailing list archive at Nabble.com.

_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat <at> www.jboss.com
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev
Harsh Jetly | 7 Aug 10:46
Favicon

[rules-dev] Problem using RuleFlows .


Hi ,
The version of Drools that I have used is 4.0.4

I have used ruleflow groups to create my rule file.
It has a split node (XOR) in which I specify a constraint on which a
ruleflow-group is to be selected .

Insert arraylists as facts in the working memory one by one.

The problem I face is that when I insert these arraylists in the same
session , it doesn't evaluate every constraint in the split node .

The work around I am using , it that I create a new session for every
arraylist , this works just fine . But creating a new session always is an
overhead .

Can you please assist me with this situation .

Thank You

Harsh Jetly

Larsen & Toubro Infotech Ltd.
www.Lntinfotech.com

This Document is classified as:

|------|
| [X]  |
|------|L&T Infotech Proprietary   |------|
                                   | [ ]  |
                                   |------|L&T Infotech Confidential   |------|
                                                                       | [ ]  |
                                                                       |------|
L&T Infotech Internal Use Only   |------|
                                 | [ ]  |
                                 |------|L&T Infotech General Business

This Email may contain confidential or privileged information for the
intended recipient (s) If you are not the intended recipient, please do not
use or disseminate the information, notify the sender and delete it from
your system.

______________________________________________________________________
_______________________________________________
rules-dev mailing list
rules-dev <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev


Gmane