OK, first thing: getBillActCode() creates an empty HashMap that is either not used or
replaced in all cases. In general you should avoid object creation in functions called in
rule conditions, but especially avoid unnecessary object creation. :)
And now for the rules. I'm not sure I've ever seen rules that so completely
circumvent all benefit of the rete algorithm. :) If all of the rules are similar (a list
of from statements that gather data from a record, then one big eval at the end) then you
don't need drools at all. If you can't change the BillingRecord into a java bean
with properties to test directly in rules then straight java might be better for you.
However, if you can do this, then add the BACAMap entries into working memory, if
possible.
If you can do both things, your rules should look like this:
rule AssignBAC
salience 50
no-loop true
when
$br:BillingRecord(
billingActionCd==null || billingActionCd==""
)
$bac:BACAMapEntry(
stationNo==$br.stationNo,
cardType==$br.cardType,
tktCurrAlphaCd==$br.tktCurrAlphaCd
)
then
modify($br){setBillingActionCd($bac.getValue());}
info(BillingRecordHelper.BAC_ASSIGNED_INFO,log);
end
And I figure rules like this will be a heck of a lot faster...
--- On Sun, 11/8/09, ABRA2 <rabarna(a)archstone.in> wrote:
From: ABRA2 <rabarna(a)archstone.in>
Subject: [rules-users] Help me improve my rules performance.
To: rules-users(a)lists.jboss.org
Date: Sunday, November 8, 2009, 11:02 PM
Hi,
I have an example of two rules we use in our project.
Rule CheckStationNumber checks if the station number field
is null in
BillingRecord Object which is
stored as a list in AssertionObject object.
Rule AssignBAC gets a value from a static map(we dont want
to do database
calls eachtime.so we store the
required values in a static map) and assigns it to bac
field in
BillingRecord based
on certain other field values in Billing Record.
So we have around 10 more rules similiar to this pattern
and we run this
rule against against
100,000 billing records and the execution time is very
long.
I know that i am not supposed to use eval in rules which
slows down the
performance. Can you please
suggest me few other ways how i can accomplish these tasks
and improve the
execution time?
thanks
ABRA2
example.drl
import ct.fw.web.rules.*;
import ct.fw.rules.*;
import ct.fw.utils.*;
import ct.fw.rules.*;
import ct.fw.pf.*;
import ct.fw.pf.dbi.DbAccess;
import ct.fw.logging.*;
import ct.fw.ex.*;
import org.apache.commons.lang.*;
import com.aa.gccp.domain.*;
import com.aa.gccp.domain.persistence.dao.*;
import com.aa.gccp.utils.*;
import com.aa.gccp.processor.*;
global ct.fw.logging.SmartLogger log
function BillingRecord
getRecord(AssertionObject ao)
{
return
(BillingRecord) ao.get(0);
}
function Object
getRecordData(AssertionObject ao, String key)
{
return getRecord(ao).get(key);
}
function void error(String
msg,SmartLogger log)
{
log.error(BusinessRulesValidator.class, msg);
}
function void info(String
msg,SmartLogger log)
{
log.info(BusinessRulesValidator.class, msg);
}
function String getBillActCode(String stationno,String
tiktcrncy,String
cardtype)
{
String bac="";
Map<String,String>
bacamap = new HashMap<String,String>();
if(stationno!=null
&& !stationno.equals("") && tiktcrncy!=null
&&
!tiktcrncy.equals("") && cardtype!=null &&
!cardtype.equals(""))
{
if(stationno.length()<7){stationno=stationno.substring(0,3);}
bacamap=FileFormatLoader.BACAMap;
if(bacamap.size()>0)
{
bac=bacamap.get(stationno+tiktcrncy+cardtype);
}
}
return bac;
}
rule CheckStationNumber
salience 100
no-loop true
when
$ao:AssertionObject()
$stno:String() from
getRecordData($ao,"stationNo")
eval(($stno.equals("")) || ($stno ==
null))
then
$ao.addError(BillingRecordHelper.STATION_NO_NULL_ERROR,"CheckStationNumber");
error(BillingRecordHelper.STATION_NO_NULL_ERROR,log);
end
rule AssignBAC
salience 50
no-loop true
when
$ao:AssertionObject()
$stno:String() from
getRecordData($ao,"stationNo")
$cardtype:String() from
getRecordData($ao,"cardType")
$tktcuralphacd:String() from
getRecordData($ao,"tktCurrAlphaCd")
$bac:String() from
getBillActCode($stno,$tktcuralphacd,$cardtype)
eval(((((getRecord($ao)).getBillingActionCd())==null)
||
(((getRecord($ao)).getBillingActionCd()).equals("")))
&& !($bac.equals("")))
then
modify($ao){setBillingRecord("billingActionCd",$bac);}
info(BillingRecordHelper.BAC_ASSIGNED_INFO,log);
end
--
View this message in context:
http://old.nabble.com/Help-me-improve-my-rules-performance.-tp26261345p26...
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