Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0037115Openbravo ERPA. Platformpublic2017-10-19 13:112017-11-20 12:43
alostale 
alostale 
normalminorhave not tried
closedfixed 
5
 
3.0PR18Q1 
caristu
Core
No
0037115: HQL constant parsing causes contention
With high concurrency contention at JVM level occurs when Hibernate is creating AST tree for queries at

        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:187)
        at org.hibernate.util.ReflectHelper.getConstantValue(ReflectHelper.java:266)


This is caused because HQL allows to include Java constant values, to determine whether a token is or not a constant it performs a classForName whenever it includes a dot, which finally reaches a synchronized block causing this contention. More info here [1].

This is a Hibernate issue HHH-4959 that's fixed starting from 5.2.6 and HHH-11377 (5.2.7).

---
[1] https://vladmihalcea.com/2016/12/14/the-performance-penalty-of-class-forname-when-parsing-jpql-and-criteria-queries/ [^]

Execute attached test case profiling monitor locks
  -Check there is huge contention at:

   java.lang.Thread.State: BLOCKED
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1200)
        
- waiting to lock <334e3ea4> (a java.lang.Object) owned by "ajp-nio-8009-exec-46" t@125
        
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:187)
        at org.hibernate.util.ReflectHelper.getConstantValue(ReflectHelper.java:266)
        at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.handleDotStructure(QueryTranslatorImpl.java:599)
        
at org.hibernate.hql.ast.QueryTranslatorImpl$JavaConstantConverter.visit(QueryTranslatorImpl.java:594)
        
at org.hibernate.hql.ast.util.NodeTraverser.visitDepthFirst(NodeTraverser.java:78)
        at org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:66)
        at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:280)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
        - locked <56ccf607> (a org.hibernate.hql.ast.QueryTranslatorImpl)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
        at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
Backport issues HHH-4959[1][2] and its related HHH-11377[3][4].

Consider bakporting only changes to ReflectHelper.java so that this is enforced and cannot be configured so the complexity of the backport is significantly reduced.

Note this would limit usage of Java constants in HQL to only those that conform "valid" Java constant convention (basically package name in lower case, Java class starting by a capital letter and constant field name all upper case: [a-z\\d]+\\.([A-Z]{1}[a-z\\d]+)+\\$?([A-Z]{1}[a-z\\d]+)*\\.[A-Z_\\$]+

---
[1] https://hibernate.atlassian.net/browse/HHH-4959 [^]
[2] https://github.com/hibernate/hibernate-orm/commit/0bd7b8 [^]
[3] https://hibernate.atlassian.net/browse/HHH-11377 [^]
[4] https://github.com/hibernate/hibernate-orm/commit/491d7341 [^]
Performance
related to feature request 0037064 closed caristu upgrade hibernate to 5.3.2 
? QueryConstantContention.java (2,305) 2017-10-27 15:15
https://issues.openbravo.com/file_download.php?file_id=11243&type=bug
png Selection_226.png (69,563) 2017-10-27 15:15
https://issues.openbravo.com/file_download.php?file_id=11244&type=bug
png

png Selection_227.png (23,962) 2017-10-27 15:16
https://issues.openbravo.com/file_download.php?file_id=11245&type=bug
png
Issue History
2017-10-19 13:11alostaleNew Issue
2017-10-19 13:11alostaleAssigned To => platform
2017-10-19 13:11alostaleModules => Core
2017-10-19 13:11alostaleTriggers an Emergency Pack => No
2017-10-19 13:12alostaleDescription Updatedbug_revision_view_page.php?rev_id=16143#r16143
2017-10-19 13:12alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=16145#r16145
2017-10-19 13:12alostaleRelationship addedrelated to 0037064
2017-10-19 13:12alostaleStatusnew => acknowledged
2017-10-19 14:07alostaleDescription Updatedbug_revision_view_page.php?rev_id=16146#r16146
2017-10-19 14:09alostaleDescription Updatedbug_revision_view_page.php?rev_id=16147#r16147
2017-10-19 14:12alostaleDescription Updatedbug_revision_view_page.php?rev_id=16148#r16148
2017-10-19 14:13alostaleDescription Updatedbug_revision_view_page.php?rev_id=16149#r16149
2017-10-27 13:18alostaleTag Attached: Performance
2017-10-27 15:14alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=16197#r16197
2017-10-27 15:15alostaleFile Added: QueryConstantContention.java
2017-10-27 15:15alostaleFile Added: Selection_226.png
2017-10-27 15:16alostaleFile Added: Selection_227.png
2017-11-13 13:09hgbotCheckin
2017-11-13 13:09hgbotNote Added: 0100480
2017-11-13 13:09hgbotStatusacknowledged => resolved
2017-11-13 13:09hgbotResolutionopen => fixed
2017-11-13 13:09hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/ea74193b74fa03750c0d26bcb2da2a1103079969 [^]
2017-11-13 13:10alostaleAssigned Toplatform => alostale
2017-11-13 13:11alostaleReview Assigned To => caristu
2017-11-20 12:43caristuNote Added: 0100619
2017-11-20 12:43caristuStatusresolved => closed
2017-11-20 12:43caristuFixed in Version => 3.0PR18Q1

Notes
(0100480)
hgbot   
2017-11-13 13:09   
Repository: erp/devel/pi
Changeset: ea74193b74fa03750c0d26bcb2da2a1103079969
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Nov 09 10:41:46 2017 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/ea74193b74fa03750c0d26bcb2da2a1103079969 [^]

fixed 37115, fixed 35271: hibernate performance improvements

  * 37115: HQL constant parsing causes contention
     Backports Hibernate issues HHH-4959 and HHH-11377, preventing in most of
     the cases to verify whether a HQL token is a constant which invokes an
     expensive classForName.

  * 35271: OBCriteria overhead
     OBCriteria caused overhead because everytime a critieria was executed, entity
     implementors (java class) was checked. As for a given entity its implementors
     are constant, they can be safelly cached. Note this cache is fixed in size as,
     at most, it will contain an entry per entity. See HHH-11495.

---
M lib/runtime/hibernate3-patched.jar
---
(0100619)
caristu   
2017-11-20 12:43   
Verified