Bug 1203984 - pre-compile MvelConstraint instead of JIT
Summary: pre-compile MvelConstraint instead of JIT
Keywords:
Status: CLOSED EOL
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.0.3
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: ---
: ---
Assignee: Mario Fusco
QA Contact: Marek Winkler
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-03-20 05:43 UTC by Toshiya Kobayashi
Modified: 2020-03-27 20:08 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2020-03-27 20:08:07 UTC
Type: Feature Request
Embargoed:


Attachments (Terms of Use)
BZ1203984_precompile.zip (99.53 KB, application/zip)
2015-04-13 09:03 UTC, Toshiya Kobayashi
no flags Details
BZ1203984_precompile.zip (2.99 MB, application/zip)
2015-04-16 10:37 UTC, Toshiya Kobayashi
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker PRODMGT-1184 0 Major Pending Product Management Triage pre-compile MvelConstraint instead of JIT 2018-02-08 09:23:54 UTC

Description Toshiya Kobayashi 2015-03-20 05:43:18 UTC
Description of problem:

When rules are heavily used (e.g. planner, batch application). Jitting MvelConstraint is not effective.

The request is a feature to pre-compile MvelConstraint instead of JIT, which could be used both
 - at building kjar time and
 - at just after kbase creation and before ksession creation.

Comment 3 Toshiya Kobayashi 2015-04-13 09:03:51 UTC
Created attachment 1013871 [details]
BZ1203984_precompile.zip

Attached BZ1203984_precompile.zip as a reproducer (by default, 500 rules).

You can run it with "mvn clean test".

The throughput trend is like this.

0 -> 1007 : throughput = 1.8262164846077458(num/ms)
1007 -> 2008 : throughput = 5.859140859140859(num/ms)
2008 -> 3008 : throughput = 9.778(num/ms)
3008 -> 4008 : throughput = 17.55(num/ms)
4008 -> 5008 : throughput = 26.639(num/ms)
5008 -> 6008 : throughput = 32.514(num/ms)
6008 -> 7009 : throughput = 32.5004995004995(num/ms)
7009 -> 8009 : throughput = 33.02(num/ms)
8009 -> 9009 : throughput = 33.891(num/ms)
...

Comment 4 Toshiya Kobayashi 2015-04-15 09:19:55 UTC
I tried to make JIT_THRESOLD configurable in my personal build.

===================
diff --git a/drools-core/src/main/java/org/drools/core/rule/constraint/MvelConstraint.java b/drools-core/src/main/java/org/drools/core/rule/constraint/MvelConstraint.java
index 3e8dcfa..1162232 100644
--- a/drools-core/src/main/java/org/drools/core/rule/constraint/MvelConstraint.java
+++ b/drools-core/src/main/java/org/drools/core/rule/constraint/MvelConstraint.java
@@ -53,7 +53,7 @@ import static org.drools.core.util.StringUtils.skipBlanks;
 
 public class MvelConstraint extends MutableTypeConstraint implements IndexableConstraint, AcceptsReadAccessor {
     protected static final boolean TEST_JITTING = false;
-    protected static final int JIT_THRESOLD = 20; // Integer.MAX_VALUE;
+    protected static final int JIT_THRESOLD; // Integer.MAX_VALUE;
 
     private static final Logger logger = LoggerFactory.getLogger(MvelConstraint.class);
 
@@ -75,6 +75,11 @@ public class MvelConstraint extends MutableTypeConstraint implements IndexableCo
     protected transient volatile ConditionEvaluator conditionEvaluator;
     private transient volatile Condition analyzedCondition;
 
+    static {
+        JIT_THRESOLD = Integer.parseInt(System.getProperty("drools.jit.threshold", "20"));
+        System.out.println("JIT_THRESOLD = " + JIT_THRESOLD);
+    }
+
     public MvelConstraint() {}
 
     public MvelConstraint(String packageName,
===================

Now I can configure JIT_THRESOLD like this:

System.setProperty("drools.jit.threshold", "1");

Here are test results of changing the threshold with my reproducer (BZ1203984_precompile.zip).

[JIT_THRESOLD = 1]
Lots of "WARN  Exception jitting" are raised so most of constraints are failed to be jitted.

2015-04-14 16:23:01,842 [Thread-1] WARN  Exception jitting: age >= 65 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:23:01,843 [Thread-4] WARN  Exception jitting: age >= 80 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
...

so resulted in lower throughput.

0 -> 1000 : throughput = 0.355(num/ms)
1000 -> 2001 : throughput = 2.076923076923077(num/ms)
2001 -> 3001 : throughput = 4.894(num/ms)
3001 -> 4005 : throughput = 4.620517928286852(num/ms)
4005 -> 5006 : throughput = 4.130869130869131(num/ms)
5006 -> 6006 : throughput = 7.454(num/ms)
6006 -> 7009 : throughput = 10.083748753738783(num/ms)
7009 -> 8009 : throughput = 9.83(num/ms)
8009 -> 9009 : throughput = 10.787(num/ms)
...

[JIT_THRESOLD = 2]
2015-04-14 16:28:52,025 [main] DEBUG Starting Engine in PHREAK mode
2015-04-14 16:28:52,324 [Thread-3] WARN  Exception jitting: age >= 40 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:28:52,469 [Thread-46] WARN  Exception jitting: age >= 1970 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:28:52,471 [Thread-17] WARN  Exception jitting: age >= 2005 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:28:52,471 [Thread-21] WARN  Exception jitting: age >= 2010 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:28:52,474 [Thread-23] WARN  Exception jitting: age >= 2065 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:28:52,481 [Thread-27] WARN  Exception jitting: age >= 2230 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
0 -> 1000 : throughput = 2.267(num/ms)
1000 -> 2013 : throughput = 5.40177690029615(num/ms)
2013 -> 3013 : throughput = 9.353(num/ms)
3013 -> 4013 : throughput = 16.991(num/ms)
4013 -> 5013 : throughput = 19.186(num/ms)
5013 -> 6014 : throughput = 31.87112887112887(num/ms)
6014 -> 7014 : throughput = 31.604(num/ms)
7014 -> 8014 : throughput = 30.859(num/ms)
8014 -> 9014 : throughput = 31.34(num/ms)
9014 -> 10014 : throughput = 32.2(num/ms)

[JIT_THRESOLD = 5]
2015-04-14 16:31:17,907 [main] DEBUG Starting Engine in PHREAK mode
2015-04-14 16:31:18,212 [Thread-3] WARN  Exception jitting: age >= 40 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:31:18,306 [Thread-2] WARN  Exception jitting: age >= 1325 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
2015-04-14 16:31:18,361 [Thread-23] WARN  Exception jitting: age >= 1975 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
0 -> 1000 : throughput = 1.713(num/ms)
2015-04-14 16:31:19,415 [Thread-38] WARN  Exception jitting: age < 140 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
1000 -> 2000 : throughput = 3.65(num/ms)
2000 -> 3000 : throughput = 7.03(num/ms)
3000 -> 4000 : throughput = 8.527(num/ms)
4000 -> 5000 : throughput = 9.644(num/ms)
5000 -> 6000 : throughput = 12.617(num/ms)
6000 -> 7001 : throughput = 28.576423576423576(num/ms)
7001 -> 8001 : throughput = 28.575(num/ms)
8001 -> 9001 : throughput = 28.115(num/ms)
9001 -> 10001 : throughput = 30.824(num/ms)
10001 -> 11001 : throughput = 31.369(num/ms)
11001 -> 12001 : throughput = 30.559(num/ms)

[JIT_THRESOLD = 10]
2015-04-14 16:32:17,280 [main] DEBUG Starting Engine in PHREAK mode
2015-04-14 16:32:17,665 [Thread-0] WARN  Exception jitting: age >= 475 This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
0 -> 1000 : throughput = 1.85(num/ms)
1000 -> 2004 : throughput = 6.070717131474104(num/ms)
2004 -> 3004 : throughput = 11.029(num/ms)
3004 -> 4004 : throughput = 15.82(num/ms)
4004 -> 5004 : throughput = 22.708(num/ms)
5004 -> 6004 : throughput = 30.65(num/ms)
6004 -> 7004 : throughput = 28.439(num/ms)
7004 -> 8005 : throughput = 28.565434565434565(num/ms)
8005 -> 9005 : throughput = 28.277(num/ms)
9005 -> 10005 : throughput = 28.131(num/ms)
10005 -> 11005 : throughput = 30.213(num/ms)
11005 -> 12005 : throughput = 29.743(num/ms)
12005 -> 13005 : throughput = 28.808(num/ms)

From [JIT_THRESOLD = 2] to [JIT_THRESOLD = 10], the results are not bad but we don't see improvement comparing to the default [JIT_THRESOLD = 20] (https://bugzilla.redhat.com/show_bug.cgi?id=1203984#c3).

Comment 5 Toshiya Kobayashi 2015-04-16 10:37:07 UTC
Created attachment 1015131 [details]
BZ1203984_precompile.zip

Updated the reproduce with minor fixes:

- Use AtomicLong instead of long for resultNum. (I think it's not a big difference in calculating the throughput but to make it precise)
- Add '1' to resultNum instead of fireNum. (With current rules, the result is the same but to make sure that the throughput means num of inserted fact / time )
- -Xmx4G by default


Note You need to log in before you can comment on or make changes to this bug.