OutOfMemoryError保持锁定:使用Excel规则文件进行Drools

时间:2014-11-12 16:37:16

标签: drools

我们实施了具有excel文件作为规则的Drools,适用于低流量但在生产中遇到OutOfMemoryErrors(> 100 req / sec)。

感谢任何建议/帮助。

错误堆栈跟踪:

  Stack 0: start=0x513d000, end=0x5161000, guards=0x5142000 (ok), forbidden=0x5140000
 Thread Stack Trace:
at jniExceptionCheck+7()@0xf7df37a7
at cmgrGenerateCode+260()@0xf7d77aa4
at generate_code2+937()@0xf7e5f7b9
at generate_code+97()@0xf7e5fa31
at get_runnable_codeinfo2+275()@0xf7e5ffe3
at get_runnable_codeinfo+25()@0xf7e60059
at RJNI_jrockit_vm_RNI_generateVirtualCode+185()@0xf7e60129
-- Java stack --
at jrockit/vm/RNI.generateVirtualCode(Ljava/lang/Object;II)I(Native Method)
at com/xxx/www/framework/drools/Rule_Name_10809963762DefaultConsequenceInvoker.setConsequence(Lorg/drools/core/spi/Consequence;)V(Unknown Source)
at org/drools/core/rule/builder/dialect/asm/ConsequenceGenerator.generate(ConsequenceGenerator.java:142)
at com/xxx/www/framework/drools/Rule_Name_10809963762DefaultConsequenceInvoker.evaluate(Lorg/drools/core/spi/KnowledgeHelper;Lorg/drools/core/WorkingMemory;)V(Unknown Source)
^-- Holding lock: com/xxx/www/framework/drools/Rule_Name_10809963762DefaultConsequenceInvoker@0x78d77348[biased lock]
at org/drools/core/common/DefaultAgenda.fireActivation(DefaultAgenda.java:1018)
^-- Holding lock: org/drools/core/common/DefaultAgenda@0x799cb318[biased lock]
at org/drools/core/phreak/RuleExecutor.fire(RuleExecutor.java:128)
at org/drools/core/phreak/RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:70)
^-- Holding lock: org/drools/core/phreak/RuleExecutor@0x5b00b628[biased lock]
at org/drools/core/common/DefaultAgenda.fireNextItem(DefaultAgenda.java:937)
at org/drools/core/common/DefaultAgenda.fireAllRules(DefaultAgenda.java:1201)
at org/drools/core/common/AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:958)
at org/drools/core/common/AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:932)
at org/drools/core/impl/StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:256)
at com/xxx/www/framework/drools/impl/MyDroolsRulesEngine.runRules(MyDroolsRulesEngine.java:163)
at com/xxx/www/framework/drools/impl/MyDroolsRulesEngine.processXLS(MyDroolsRulesEngine.java:88)
at com/xxx/www/framework/drools/MyDroolsRuleEngineHelper.processRule(MyDroolsRuleEngineHelper.java:74)

实现:

     public abstract class MyDroolsRulesEngine{

     private KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
     private KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

    /*calling drools by passing excel rules as inputstream and inputFact*/
    public Object processXLS(InputStream inputStream, Object inputFact) {

    if(inputStream!=null){
        DecisionTableConfiguration dtableconfiguration = getDesisionTableConfiguration();
        kbuilder.add(ResourceFactory.newInputStreamResource(inputStream), ResourceType.DTABLE, dtableconfiguration);
        runRules(inputFact); /* calling drools to trigger rule execution */
        return inputFact;
    }
    return null;
    }

    private void runRules(Object inputFact){
    try {
    if ( kbuilder.hasErrors() ) {
            System.err.println( kbuilder.getErrors().toString() );
    }

    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    knowledgeSession = kbase.newStatefulKnowledgeSession(); /* new statefullsession for each web session */
    knowledgeSession.insert(inputFact); /* inputFact has only 2-3 variables/values to validate in rule condition */
    knowledgeSession.fireAllRules();
    knowledgeSession.dispose(); /* disposing statefullsession after execution */
    } catch (Exception e) {
        LOG.error("Exception  :", null, e);
    }
}

DecisionTable excel规则

   RuleTable Rule Name      
    CONDITION                  CONDITION      ACTION
    input: InputFact        
    var1 >= $1, var1 <= $2    var2            input.setResponse("$param");
     0,5                        test              02

0 个答案:

没有答案