Iti Gupta
Iti Gupta

Reputation: 189

GC Out of Memory in Drools Rule Engine in Spring Boot project

I need to compare data of two Lists based on two fields and if the data matches then add it to another list.

The Rule I have written is working fine but when I'm trying to test it for more records(say 10,000 records) it's throwing GC Out of Memory error.

For this I'm adding Both the lists(facts) in the working memory.The code for adding it is given below:

   // insert List 1
    list1.stream().forEach(p -> kieSession.insert(p));
    // insert List 2
    list2.stream().forEach(p ->kieSession.insert(p));

Both these lists have the same fields.Now, I need to check if the data of field1 and field2 of list1 matches with that of list2.The code of the Rule I've written is as follows:

       rule "To check list1 and list2" 
        salience 5
        no-loop true
           when
                list1: List1($field1:field1,$field2:field2)
                list2: List2($field1List2:field1,$field2List2:field2)
                eval($field1List2==$field1&&$field2List2==$field2)
            then
                globalList.add(list2);
                retract(list1);
                retract(list2);
        end

I'm not able to figure out the cause of GC out of memory.

Whether I'm doing something wrong with the Rules or I need to increase JVM memory?

Currently, the JVM memory is -Xms2048m.

Upvotes: 1

Views: 701

Answers (1)

舒远夏
舒远夏

Reputation: 11

Drools is based on Rete arithmetic, so it will take O(m*n) time and memory to do the CROSS-JOIN work, which causes bad performance and OOM easily. Try not to write join condition in rules, do the join work outside the work memory.

Upvotes: 1

Related Questions