[rules-users] populating global variable in Condition Section?

Greg Barton greg_barton at yahoo.com
Fri Aug 21 23:44:53 EDT 2009


Of course, I had to test that assertion. :)

$ java -Xmx128M -server -jar target/DroolsExistence-1.0.jar not.drl 50000
25000
2395ms
$ java -Xmx1024M -server -jar target/DroolsExistence-1.0.jar not_exists.drl 50000
25000
121378ms

You ain't kiddin'! 50x slower requiring 9x the memory.

--- On Fri, 8/21/09, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:

> From: Wolfgang Laun <wolfgang.laun at gmail.com>
> Subject: Re: [rules-users] populating global variable in Condition Section?
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Friday, August 21, 2009, 4:54 PM
>  <quote>
> It is rather common for people to
>             write something like "(not (exists
> (A)))," but this is just a
>             very inefficient way to write (not
> (A)).
> </quote> 
> 
> Kudos to Ernest Friedman-Hill to put this sentence into the
> Jess documentation.
> 
> Maybe I should quote hiom in the Drools Expert doc ;-)
> 
> 
> -W
> 
> 
> On Fri, Aug 21, 2009 at 11:11 PM,
> Shah, Malay <Malay.Shah at morganstanley.com>
> wrote:
> 
> May be I have not put the question right. We have a drool
> rule that is running extremely slow for large sets of data.
> The rule is something like:
> 
> 
> 
> For every object A, perform action if there does not exist
> an object B such that A.id = B.id.
> 
> And the corresponding drool rule is as follows:
> 
> 
> 
> when
> 
>     A()
> 
>     not(exists B(A.id = id))
> 
> then
> 
>     action......
> 
> 
> 
> The performance is bad because of not exists clause here.
> We have got OOM exceptions with relatively large amounts of
> data for this rule. To improve performance, we basically
> hacked the rule/code into something like this:
> 
> 
> 
> 
> Create a global variable x that is a HashSet of all ids of
> object A, and the drool rule now is:
> 
> 
> 
>  global java.util.HashSet x;
> 
> when
> 
>         B()
> 
>         eval
> 
>         (
> 
>                 ! (x.contains(b.id) )
> 
>         )
> 
> then
> 
>         action.....
> 
> 
> 
> This obviously is performing much better with hashes
> involved. But, I don't like the fact that we have to
> write the logic of this rule at two places. I would rather
> create this variable x (don't care whether it is global
> or temporarily bound) in the rule itself and use it in the
> condition to help performance and have all logic for the
> rule at one place.
> 
> 
> 
> 
> Is there a way to generate this hashset x in the condition
> part of the rule itself? Yes, I understand that I am trying
> to mix up the procedural part of code with drool code. But,
> I was just wondering if this is possible to keep the java
> code clean and have the intelligence of information that the
> rule needs to be evaluated in the rule itself.
> 
> 
> 
> 
> Hope this clears some doubts.
> 
> 
> 
> Thanks
> 
> 
> 
> Malay Shah
> 
> 
> 
> -----Original Message-----
> 
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org]
> On Behalf Of Greg Barton
> 
> 
> Sent: Friday, August 21, 2009 4:44 PM
> 
> To: Rules Users List
> 
> Subject: Re: [rules-users] populating global variable in
> Condition Section?
> 
> 
> 
> This is a galactically bad idea.  Using a global in this
> way is inherently unsafe as there's no guarantee that
> ebtween the time you set the var and when it's used
> later in the condition that the value is the same.  What is
> your reason for wanting to use a global in this way?  You
> should use a temporary bound variable instead.
> 
> 
> 
> 
> --- On Fri, 8/21/09, Shah, Malay <Malay.Shah at morganstanley.com>
> wrote:
> 
> 
> 
> > From: Shah, Malay <Malay.Shah at morganstanley.com>
> 
> > Subject: [rules-users] populating global variable in
> Condition Section?
> 
> > To: rules-users at lists.jboss.org
> 
> > Date: Friday, August 21, 2009, 3:19 PM
> 
> >
> 
> >
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > Hi,
> 
> >
> 
> > Is it possible
> 
> > to populate a global variable in
> 
> > the condition section of the
> 
> > drool rule, and use it later in the condition itself?
> 
> > I currently have a
> 
> > global HashSet variable that I construct before firing
> the rule, but I
> 
> > would like this code of constructing this global
> variable to be with
> 
> > the drool rule itself. Any help on this would be much
> appreciated.
> 
> >
> 
> > Thanks
> 
> >
> 
> > Malay
> 
> >
> 
> >
> 
> >
> 
> > NOTICE: If received in error, please
> 
> > destroy, and notify sender. Sender does not intend to
> waive
> 
> > confidentiality or privilege. Use of this email is
> 
> > prohibited when received in error. We may monitor and
> store emails to the extent
> 
> > permitted by applicable law.
> 
> >
> 
> >
> 
> > -----Inline Attachment Follows-----
> 
> >
> 
> > _______________________________________________
> 
> > 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
> 
> 
> 
> --------------------------------------------------------------------------
> 
> NOTICE: If received in error, please
> destroy, and notify sender. Sender does not intend to waive
> confidentiality or privilege. Use of this email is
> prohibited when received in error. We may monitor and store
> emails to the extent permitted by applicable law.
> 
> 
> 
> 
> _______________________________________________
> 
> rules-users mailing list
> 
> rules-users at lists.jboss.org
> 
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 
> 
> 
> -----Inline Attachment Follows-----
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DroolsExistence.tar.gz
Type: application/x-gzip
Size: 4888 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20090821/9fd36ad8/attachment.gz 


More information about the rules-users mailing list