It's happening because the problem is hard. :) It's quadratic on the average
number of assignments per driver. i.e. for each driver, you compare all of the
assignments to each other, and you must do that for all drivers. So you have ( (num
drivers) * (average num assignments)^2 ) firings in the BEST case. (The rule you
originally presented was pretty much the worst case, as you were matching ( (num
drivers)^2 *(num trips)^2 ) )
That's also why the processing happens when you insert the second set: before that the
rule doesn't trigger.
Now, if you don't need to compare trip assignments between drivers, you could just
insert one driver plus their trips and fire the rules.
But if you do want to throw everything in WM at once, you may be able to use this trick:
to detect overlap, you can cut the number of conditions you've got in half, making
things slightly better. You only need to detect that the start or end of one of the trips
is contained in another. Also, is it possible to have a driverId attribute in your trip
object? That would eliminate the need to match on the driver object. Using both
you'd have this:
rule "Assignment Check"
when
$ta1: TripVO();
$ta2: TripVO(
ta1.driverId == driverId,
ta1.startDtmUtc < startDtmUtc,
ta1.endDtmUtc >= startDtmUtc
);
then
Note the "ta1.startDtmUtc < startDtmUtc" instead of ta1.startDtmUtc <=
startDtmUtc". This ensures that you don't test the same two TripVOs twice.
Give this a try.
--- On Mon, 6/1/09, jayadevan.m(a)gmail.com <jayadevan.m(a)gmail.com> wrote:
From: jayadevan.m(a)gmail.com <jayadevan.m(a)gmail.com>
Subject: Re: Re: Re: [rules-users] Re: Drools performance issue
To: "Wolfgang Laun" <wolfgang.laun(a)gmail.com>
Cc: rules-users(a)lists.jboss.org
Date: Monday, June 1, 2009, 8:34 AM
Hi,
I noticed something interesting. The issue with
memory is happening always while inserting the second set of
objects into working memory!
Earlier, I was insering the DriverVO's into WM
and then inserting the AssignmentsVO, and the system was
hanging while inserting the AssignmentsVO. Then I reversed
the order of insertion and then the machine was hit while
inserting the DriverVO's.
Does anyone know why this issue might be happening
and how to overcome this?
Thanks in advance,
Jayadevan.
On Jun 1, 2009 6:51pm, jayadevan.m(a)gmail.com wrote:
> Thanks W,
>
>
>
>
>
> I tried it out ,But didn't get any
performance improvement :(
>
>
> The issue might be that I am inserting too many
objects into working memory
>
>
>
>
>
> jayadevan
>
>
>
>
>
> On Jun 1, 2009 3:36pm, Wolfgang Laun
wolfgang.laun(a)gmail.com> wrote:
>
>
> > The first two patterns pair each driver
assignment with each trip -
>
>
> >
>
>
> >
>
>
> > which is quite a lot of work to do. (The
infix "and" between the 2nd
>
>
> >
>
>
> >
>
>
> > and 3rd pattern doesn't change this.)
Also, the field restriction
>
>
> >
>
>
> >
>
>
> > "tripId in ($tid)" is not the
most efficient way.
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > Try this:
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > rule "Assignment Check"
>
>
> >
>
>
> >
>
>
> > when
>
>
> >
>
>
> >
>
>
> > $creVo: DriverAssignVO($drId: driverId,
$tid1: tripId)
>
>
> >
>
>
> >
>
>
> > $creVo: DriverAssignVO(driverId ==
$drId, $tid2: tripId != $tid1)
>
>
> >
>
>
> >
>
>
> > $trAsgn1: TripVO( tripId == $tid1,
$startDtmUtc: startDtmUtc,
>
>
> >
>
>
> >
>
>
> > $endDtmUtc: endDtmUtc)
>
>
> >
>
>
> >
>
>
> > $trAsgn2: TripVO( tripId == $tid2,
>
>
> >
>
>
> >
>
>
> > ((startDtmUtc
>= $startDtmUtc && startDtmUtc
>
>
> >
>
>
> > (endDtmUtc >=
$startDtmUtc && endDtmUtc
>
>
> >
>
>
> > then
>
>
> >
>
>
> >
>
>
> > System.out.println("TRIP ID: "
+ $crvo.getTripId());
>
>
> >
>
>
> >
>
>
> > end
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > Here the first two patterns produce all
pairs of assignments of a
>
>
> >
>
>
> >
>
>
> > single driver, and the remainder checks for
overlaps.
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > You'll also find that this produces two
symmetric firings for each
>
>
> >
>
>
> >
>
>
> > overlap. It might be possible to avoid this
by using "$tid2: tripId >
>
>
> >
>
>
> >
>
>
> > $tid1" in the second pattern, the
id's data type permitting.
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > -W
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> > 2009/6/1 Mark Proctor
mproctor(a)redhat.com>:
>
>
> >
>
>
> >
>
>
> > > Please send these emails to the user
list (in cc) so everyone can help, not
>
>
> >
>
>
> >
>
>
> > > directly to me.
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Mark
>
>
> >
>
>
> >
>
>
> > > jayadevan m wrote:
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Hi
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > We have one performance(memory)
issue in drools-5
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Our Scenario
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > We have 3 entities
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Trip - Entity representing details
about trip
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Driver - Entity for driver , it
contain details about driver
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Assignments - details about each
assignments (one driver may assigned to
>
>
> >
>
>
> >
>
>
> > > many trip)
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > The rule is to find ,"Find
overlapping between trip assignments"
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > For Implementing this we take the
Trip ,Driver And Assignments entities
>
>
> >
>
>
> >
>
>
> > > from Data base and put it into working
memory
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > For Small number of records this
rule work well ,
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > But we want to check it against 15000
driver ,331176 assignments and 12745
>
>
> >
>
>
> >
>
>
> > > trips
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > In that case it take huge amount of
time for execution (rule firing )
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > Rule is
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > rule "Assignment Check"
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > when
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > $creVo:
DriverAssignVO($drId: driverId ,$tid: tripId);
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
$tripAssignment: TripVO(
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
$tpid: tripId,
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
$startDtmUtc: startDtmUtc,
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
$endDtmUtc: endDtmUtc)
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
and
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
$trvo: TripVO(
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
tripId != $tpid,
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
tripId in ($tid),
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
((startDtmUtc >= $startDtmUtc
&& startDtmUtc
>
>
> >
>
>
> > > $endDtmUtc) ||
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
(endDtmUtc >= $startDtmUtc &&
endDtmUtc
>
>
> >
>
>
> > > $endDtmUtc)));
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > $crvo:
DriverAssignVO($drvrId: driverId , driverId == $drId ,
>
>
> >
>
>
> >
>
>
> > > tripId != $tid, tripId == $tpid)
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > then
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
System.out.println("TRIP ID: " +
$crvo.getTripId());
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > end
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > > thanks and regards
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
_______________________________________________
>
>
> >
>
>
> >
>
>
> > > rules-users mailing list
>
>
> >
>
>
> >
>
>
> > > rules-users(a)lists.jboss.org
>
>
> >
>
>
> >
>
>
> > >
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> > >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
>
>
> >
_______________________________________________
>
>
> >
>
>
> >
>
>
> > rules-users mailing list
>
>
> >
>
>
> >
>
>
> > rules-users(a)lists.jboss.org
>
>
> >
>
>
> >
>
>
> >
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> >
>
>
> >
>
>
> >
-----Inline Attachment Follows-----
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users