0
votes

we are using drools 5.5 final version.we have thousands of objects and two rules so we are getting objects in chunk(100 size) wise and creating knowledge base for every chunk and firing rules.since creation of Knowledge Base is expensive we are getting performance issue.So we are creating Knowledge Base once and using that knowledge base for every chunk in this case after 4 to 5 chunks got executed from 6th chunk on wards rules are not getting fired though match is there .please suggest what can be done.

sample code

public static KnowledgeBase getPackageKnowledgeBase(PackageDescr pkg){

        KnowledgeBuilderConfiguration builderConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(builderConf);
        kbuilder.add(ResourceFactory.newDescrResource(pkg), ResourceType.DESCR);
        Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
        if(kbuilder.hasErrors()){
            LOGGER.error(kbuilder.getErrors());
        }
        KnowledgePackage knowledgePackage = kpkgs.iterator().next();
        KnowledgeBase kbase= KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(Collections.singletonList(knowledgePackage));
        return kbase;
}

using method

        chunkSize=100;
        int start = 0; 
        Count = -1;
                KnowledgeBase kbase=getPackageKnowledgeBase(pkgdscr)//pkgdscr contails all rules got from db

                        while(Count!=0 && Count <= chunkSize ){
                        LOGGER.debug("Deduction not getting "+mappedCustomerId);
                        Objects inputObjects = handler.getPaginatedInputObjects(start);
                        Count = inputObjects.size();
                          start=start+chunkSize;

                    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
                        for(Object object:inputObjects){
                                ksession.insert(object);
                            }

                        ksession.fireAllRules();

                         ksession.dispose();

                        }
1
No code, no way of telling. - laune
any one can please suggest - user2031558
Well, the code is neither syntactically correct nor does it match the text of your original question. Try again, and make sure that the code you post is complete (!) and reproduces the error you are describing. - Perhaps not incrementing Count is (part of) your problem but it is hard to tell from this mess of code. - laune
updated code please let me know what else you are expecting ,count is proper ,we are able to get next chunk of data properly i just given sample code how am using knowledgebase. - user2031558

1 Answers

0
votes

Below is the essential part of your loop. Looks to me that this loop terminates as soon as Count exceeds chunkSize (100). You sure this never happens?

  while(Count!=0 && Count <= chunkSize ){             
      Objects inputObjects = ...;
      Count = inputObjects.size();
      ...
      StatefulKnowledgeSession ksession = ...;
      for(Object object:inputObjects){
          ksession.insert(object);
      }
      ksession.fireAllRules();
      ...
  }