The key difference of using collections over working memory is what happens when you
update a fact.
When you use update/modify you tell drools that that object has changed. Drools then works
out which rules are affected by the change and re-computes the affected part of the rule
and triggers them as necessary. If you are reasoning off a list then when the object
containing the list is updated all the rules that depend on the list has to be
re-evaluated from scratch, even if the change didn't actually affect the list.
If you use working memory then drools can manage the lists of matching values internally
and actually know which individual item has changed. It depends on the nature of your
rules and what you are doing as to whether the performance difference is a big issue or
not, if you aren't modifying the objects then I don't believe it will make a
significant difference. If you are modifying the objects I'd make the children have a
reference to their parent and reason using joins of that.
Are you wanting the below rules to fire once per child or just once? If it is the latter
use "exists" so that it is only fired once and is likely to require less
processing.
Thomas
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-
bounces(a)lists.jboss.org] On Behalf Of Evert Penninckx
Sent: 18 June 2010 08:13
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Accessing collections in conditional statements
(inside/outside working memory)
Hi
I'm having trouble understanding how collections are accessed in conditions
and what this means in terms of perfomance. My app has concepts with a
unidirectional composite relation. Making it bidirectional, as suggested in
other posts, is really not preferred. This is the most natural model for
this business.
declare Parent
children : Collection // Collection<Child>
end
declare Child
anAttribute : String
end
With this set-up, I can think of only two rules to check for the existence
of a child and only one to check for the absence (without starting to check
for the size of a populated list, which seems farfetched and unreadable):
rule "01 - Parent has child - using contains"
when
$child : Child( )
Parent( children contains $child )
then
// do stuff
end
rule "02 - Parent has child - using from"
when
$parent : Parent( )
Child( ) from $parent.children
then
// do stuff
end
rule "03 - Parent does not have child - using from"
when
$parent : Parent( )
not Child( ) from $parent.children
then
// do stuff
end
1) Is the cost of the "contains" in rule 01 the same as the "from" in
rule
02? Why (not)? If so, inserting the Child facts in the working memory seems
not necessary.
2) I read in other posts and the user guide that putting all facts in
working memory should be faster. Is it correct to say, that the perfomance
gain will only be achieved when not using the "from" CE and thus only by
using a bi-directional relation between Parent and Child?
In any case, it seems to me that stuffing child objects into working memory
shouldn't be the concern of a client calling a "rule service". So should
this be more optimal, I'd make the rules insert the facts using an
agenda/ruleflow to make sure everything is inserted before doing the
business stuff.
Greetz
-Evert
---
If you are posting a question, please try search first. Your question may
have already been answered.
Don't post repeatedly. Wait for a few days. People will read your post by
email.
--
View this message in context:
http://drools-java-rules-
engine.46999.n3.nabble.com/Accessing-collections-in-conditional-statements-
inside-outside-working-memory-tp905005p905005.html
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************