[rules-users] How to make this rule more memory efficient?

Wolfgang Laun wolfgang.laun at gmail.com
Mon Apr 26 13:23:37 EDT 2010


The general idea of the inverted approach shown below is to keep the
fan-out in the Rete network as small as possible. Note the id >
$proxy1.id, which reduces the ProxyCells that are considered. Also,
the lookup of the the name if $proxy2 in the references of $cell1
should keep things bounded.  - I hope I got alle the 1s and 2s right,
but you should get the general idea ;-)

rule "Check consistent references"
when
        $proxy1 : ProxyCell()
        $cell1  : Cell( id == $proxy1.id )
        $proxy2 : ProxyCell( id > $proxy1.id,
                             eval( $cell1.references contains this.name ) )
        $cell2  : Cell( id == $proxy2.id,
                        eval( this.references not contains $proxy1.name ) )
then
        //report an error.....
end

-W

2010/4/26 Ryan Fitzgerald <ryan.fitzgerald at ericsson.com>:
> Hi,
>
> Can anyone advise me on how to make a drools rule more memory efficient?
> Here is the problem:
>
> I have a Cell and a ProxyCell object classes.
>
> The ProxyCell represents the Cell when their internal ID's match.
>
> Each Cell and ProxyCell however has a unique name (not same as ID).
>
> A Cell can reference (by name) a ProxyCell (as long as the ProxyCell does
> not represent that actual Cell - which would effectively be a self-reference
> and is not allowed).
>
> What I want to do is find out where I have a reference from any instance of
> Cell - cell1 - to any instance of ProxyCell - proxycell2 - but am missing a
> reference from cell2 to proxycell1 where proxycell2 is a representation of
> cell2 and proxycell1 is a representation of cell1.
>
> Here is the rule I have written for it:
>
> rule "Check consistent references"
> when
>         $cell1 : Cell()
>         $cell2 : Cell()
>         $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references contains
> this.name )
>         $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references not
> contains this.name )
> then
>         //report an error.....
> end
>
>
> I have 10,000 instances of Cell and 10,000 instances of ProxyCell in working
> memory. For each instance of Cell, it can have references to 60 different
> ProxyCell instances. Loading the Cell and ProxyCell instances into working
> memory is not a problem. However, when I try to run this rule above, the
> memory quickly goes above 1GB and I eventually get an out of memory error.
>
> I was wondering if there is a better way to structure or write this rule so
> that it doesn't use so much memory.
>
> Thanks,
> Ryan.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list