Optimization Drools规则优化
我目前正试图找到一种优化规则的方法,但不幸的是,我目前没有找到任何方法,首先让我向您展示该规则,并给出一些解释:Optimization Drools规则优化,optimization,drools,rules,rule-engine,accumulate,Optimization,Drools,Rules,Rule Engine,Accumulate,我目前正试图找到一种优化规则的方法,但不幸的是,我目前没有找到任何方法,首先让我向您展示该规则,并给出一些解释: rule "count_asset" dialect "mvel" when RuleConfig( ref_rule_code == "count_asset", $paramValue:param_value, $operator:ref_rule_operator_code, $value:value, $target:ref_rule_target_code )
rule "count_asset"
dialect "mvel"
when
RuleConfig( ref_rule_code == "count_asset", $paramValue:param_value, $operator:ref_rule_operator_code, $value:value, $target:ref_rule_target_code )
RefRuleTarget ( code == $target, $targetUsage:usage_in_rules.split("\\s*,\\s*"))
CustomerRefSubscription ( $customerId:customer_id, ref_subscription_code == 'PAT', deactivated_at == null )
Number( Utils.compare( String.valueOf(this), $operator, $value ) == true ) from accumulate (
Asset($tableId:id, customer_id == $customerId, ($paramValue == null || ref_asset_category == $paramValue))
and exists VAssetWithOwner( id == $tableId, $targetUsage contains owner ), count(1))
then
RuleResult $ruleResult = new RuleResult($customerId ...);
insert( $ruleResult );
end
此规则的作用是:它查找所有$customerId,其资产数量与RuleConfig提供的所有条件相匹配
数据示例:
RuleConfig( ref_rule_code == "count_asset", param_value = 'A', ref_rule_operator_code = '==', value = 1, ref_rule_target_code = 'G1' )
RefRuleTarget ( code = 'G1', usage_in_rules = 'A,B,C,D' )
CustomerRefSubscription ( customer_id = 1, ...)
CustomerRefSubscription ( customer_id = 2, ...)
Asset( id = 1, customer_id = 1, ref_asset_category = A)
VAssetWithOwner( id = 1, owner = A )
VAssetWithOwner( id = 1, owner = B)
Asset( id = 2, customer_id = 1, ref_asset_category = A)
VAssetWithOwner( id = 1, owner = E)
Asset( id = 3, customer_id = 1, ref_asset_category = B)
VAssetWithOwner( id = 1, owner = A)
Asset( id = 4, customer_id = 2, ref_asset_category = B)
这里,唯一一个匹配所有条件的客户id是1:他只有一个(=1)A类资产,所有者在(A、B、C、D)中
如果我只在数据库中插入一个RuleConfig,例如示例中的这个,那么我运行drools(作为一个带有fireAllRules()的java独立应用程序),需要199毫秒才能得到符合条件的客户的完整列表。
但是我插入的RuleConfig越多,花费的时间就越多
Number of Rule Config Time in ms
1 199
2 1960
3 7652
4 15156
5 35185
6 56447
7 68047
8 78541
9 86769
10 94623
11 108515
12 117124
13 129775
超过2分钟,仅13个规则配置。我的数据库包含大约1200个CustomerRefSubscription、28000个Asset和36000个VAssetWithOwner
如何改进此规则?我的数据库中可能有100多个规则配置,这样做,需要花费数小时才能返回一些结果
我已经发现删除这个部分“并且存在VAssetWithOwner(id=$tableId,$targetUsage contains owner)”在13个规则配置中变为129000ms到900ms,这是一个很大的改进,但我真的需要这个过滤器。。。我不能把它拿走
谢谢,
纪尧姆当你的规则受阻时,你需要改变你的写作风格,见答案