Anonymous | Login
Project:
RSS
  
News | My View | View Issues | Roadmap | Summary

View Issue DetailsJump to Notes ] Issue History ] Print ]
ID
0037115
TypeCategorySeverityReproducibilityDate SubmittedLast Update
design defect[Openbravo ERP] A. Platformminorhave not tried2017-10-19 13:112017-11-20 12:43
ReporteralostaleView Statuspublic 
Assigned Toalostale 
PrioritynormalResolutionfixedFixed in Version3.0PR18Q1
StatusclosedFix in branchFixed in SCM revisionea74193b74fa
ProjectionnoneETAnoneTarget Version
OSAnyDatabaseAnyJava version
OS VersionDatabase versionAnt version
Product VersionSCM revision 
Review Assigned Tocaristu
Web browser
ModulesCore
Regression level
Regression date
Regression introduced in release
Regression introduced by commit
Triggers an Emergency PackNo
Summary

0037115: HQL constant parsing causes contention

DescriptionWith 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/ [^]

Steps To ReproduceExecute 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)
Proposed SolutionBackport 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 [^]
TagsPerformance
Attached Files? file icon QueryConstantContention.java [^] (2,305 bytes) 2017-10-27 15:15
png file icon Selection_226.png [^] (69,563 bytes) 2017-10-27 15:15


png file icon Selection_227.png [^] (23,962 bytes) 2017-10-27 15:16

- Relationships Relation Graph ] Dependency Graph ]
related to feature request 0037064 closedcaristu upgrade hibernate 

-  Notes
(0100480)
hgbot (developer)
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 (developer)
2017-11-20 12:43

Verified

- Issue History
Date Modified Username Field Change
2017-10-19 13:11 alostale New Issue
2017-10-19 13:11 alostale Assigned To => platform
2017-10-19 13:11 alostale Modules => Core
2017-10-19 13:11 alostale Triggers an Emergency Pack => No
2017-10-19 13:12 alostale Description Updated View Revisions
2017-10-19 13:12 alostale Steps to Reproduce Updated View Revisions
2017-10-19 13:12 alostale Relationship added related to 0037064
2017-10-19 13:12 alostale Status new => acknowledged
2017-10-19 14:07 alostale Description Updated View Revisions
2017-10-19 14:09 alostale Description Updated View Revisions
2017-10-19 14:12 alostale Description Updated View Revisions
2017-10-19 14:13 alostale Description Updated View Revisions
2017-10-27 13:18 alostale Tag Attached: Performance
2017-10-27 15:14 alostale Steps to Reproduce Updated View Revisions
2017-10-27 15:15 alostale File Added: QueryConstantContention.java
2017-10-27 15:15 alostale File Added: Selection_226.png
2017-10-27 15:16 alostale File Added: Selection_227.png
2017-11-13 13:09 hgbot Checkin
2017-11-13 13:09 hgbot Note Added: 0100480
2017-11-13 13:09 hgbot Status acknowledged => resolved
2017-11-13 13:09 hgbot Resolution open => fixed
2017-11-13 13:09 hgbot Fixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/ea74193b74fa03750c0d26bcb2da2a1103079969 [^]
2017-11-13 13:10 alostale Assigned To platform => alostale
2017-11-13 13:11 alostale Review Assigned To => caristu
2017-11-20 12:43 caristu Note Added: 0100619
2017-11-20 12:43 caristu Status resolved => closed
2017-11-20 12:43 caristu Fixed in Version => 3.0PR18Q1


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker