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

View Issue DetailsJump to Notes ] Issue History ] Print ]
ID
0020515
TypeCategorySeverityReproducibilityDate SubmittedLast Update
design defect[Openbravo ERP] A. Platformmajorhave not tried2012-05-15 17:182017-03-15 20:19
ReporteralostaleView Statuspublic 
Assigned Toalostale 
PrioritynormalResolutionfixedFixed in Version3.0PR17Q2
StatusclosedFix in branchFixed in SCM revision0e3c102ec91e
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

0020515: OBCriteria creates contention at JVM

DescriptionOBCriteria is still adding more overhead than OBQuery, after fix 0020485 it is slower.

Note this measurement is just for overhead and not for query itself.

Profiling attached test cases, it can be seen most of the time is spent in class loading triggered by Hibernate criteria (cpu-time.png). An additional problem is this classloading is synchronized by class name (lock-monitor.png), this in practice means, concurrent threads needs to wait these locks to be released in order to execute the criteria.

The problem is the className SessionFactoryImpl.getImplementors receives [1] is not actually a classname but entity name, so ReflectHelper.classForName finally performs a locking Class.forName [2]

[1] https://github.com/alostale/hibernate-orm/blob/3.6.3-patched/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java#L827 [^]
[2] https://github.com/alostale/hibernate-orm/blob/3.6.3-patched/hibernate-core/src/main/java/org/hibernate/util/ReflectHelper.java#L192 [^]
Steps To ReproduceExecute attached test cases which executes 50000 times a very simple sql comparing times between OBCriteria and OBQuery. These 50000 executions are done splitting them from 1 to 8 threads.

The results in a laptop with 8 cores are:

Criteria with 1 threads done in 14985 ms
Criteria with 2 threads done in 13768 ms
Criteria with 3 threads done in 14811 ms
Criteria with 4 threads done in 14988 ms
Criteria with 5 threads done in 15200 ms
Criteria with 6 threads done in 15388 ms
Criteria with 7 threads done in 15311 ms
Criteria with 8 threads done in 15401 ms

Query with 1 threads done in 3728 ms
Query with 2 threads done in 1743 ms
Query with 3 threads done in 1287 ms
Query with 4 threads done in 1187 ms
Query with 5 threads done in 1121 ms
Query with 6 threads done in 1067 ms
Query with 7 threads done in 1000 ms
Query with 8 threads done in 955 ms

Here we can see OBCriteria overhead is 5 times OBQuery's. But not only that, but parallel executions do not improve throughput in criteria's case.
Proposed SolutionWhen creating the criteria, use the actual class name implementing the entity rather than entity's name so the class lookup can be done faster.

Doing it the overhead is partially reduced, but the locking is much better.

These are the results of the same executions done before, where can be seen it scales much better with multiple threads than before.

Criteria with 1 threads done in 10717 ms
Criteria with 2 threads done in 4915 ms
Criteria with 3 threads done in 3317 ms
Criteria with 4 threads done in 2796 ms
Criteria with 5 threads done in 2563 ms
Criteria with 6 threads done in 2486 ms
Criteria with 7 threads done in 2265 ms
Criteria with 8 threads done in 2176 ms
TagsPerformance
Attached Files? file icon CriteriaVsQuery.java [^] (3,459 bytes) 2017-02-15 12:38
png file icon cpu-time.png [^] (34,108 bytes) 2017-02-15 12:59


png file icon lock-monitor.png [^] (32,517 bytes) 2017-02-15 13:00

- Relationships Relation Graph ] Dependency Graph ]
related to design defect 0020611 closedalostale OBCriteria doesn't support ScrollabeResults 
related to feature request 00206663.0MP13 closedmtaal Allow creation of proxy when setting property in business object 
related to defect 00204853.0MP12 closedalostale Slow OBCriteria 
related to design defect 0035271 closedalostale OBCriteria overhead 
related to design defect 0037015 closedalostale contention in DAL proxies with high concurrency 

-  Notes
(0048728)
mtaal (manager)
2012-05-17 12:08

Note, that in the 20485 issue the performance hit was in the classloading, apparently the hibernate Criteria logic does a lot of getMappedClass calls which calls classloaders which is very slow.

It can make sense to check this again, but ofcourse the issue can also be in other places...
(0049621)
hgbot (developer)
2012-06-05 15:36

Repository: erp/devel/pi
Changeset: 0f69dacb316f5bed970bc499faf8cdd9004b25f4
Author: Martin Taal <martin.taal <at> openbravo.com>
Date: Tue Jun 05 13:06:49 2012 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/0f69dacb316f5bed970bc499faf8cdd9004b25f4 [^]

Related to issue 20515: Slow OBCriteria
Change the way order by is done to follow the standard approach of hibernate Criteria, resulting in a better joining of the order by table/property

---
M src/org/openbravo/dal/service/OBCriteria.java
---
(0049623)
hgbot (developer)
2012-06-05 15:36

Repository: erp/devel/pi
Changeset: 551e33daa248aa2d1e4989cc4dae80263dcf8119
Author: Martin Taal <martin.taal <at> openbravo.com>
Date: Tue Jun 05 13:08:30 2012 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/551e33daa248aa2d1e4989cc4dae80263dcf8119 [^]

Related to issue 20515: Slow OBCriteria
Enhanced obcriteria testcase

---
M src-test/org/openbravo/test/dal/DalPerformanceCriteriaTest.java
---
(0049624)
hgbot (developer)
2012-06-05 15:36

Repository: erp/devel/pi
Changeset: f91001dc95e53f6a8fa6964e93e126a6def9adad
Author: Martin Taal <martin.taal <at> openbravo.com>
Date: Tue Jun 05 15:34:12 2012 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/f91001dc95e53f6a8fa6964e93e126a6def9adad [^]

Related to issue 20515: Slow OBCriteria
Some additional test queries and printing of results

---
M src-test/org/openbravo/test/dal/DalPerformanceCriteriaTest.java
---
(0052334)
AugustoMauch (manager)
2012-09-24 12:53

Effort: 10
Impact: high
Plan: mid
(0094382)
hgbot (developer)
2017-02-16 10:25

Repository: erp/devel/pi
Changeset: 0e3c102ec91e2102fbdacc049b48986a400809b7
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Wed Feb 15 14:13:23 2017 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/0e3c102ec91e2102fbdacc049b48986a400809b7 [^]

fixed issue 20515: OBCriteria creates contention at JVM

  When using OBCriteria for same entity by several concurrent threads, there was
  contention at JVM due to locks in Class.forName(entityName).

  This Class.forName(entityName) always results in ClassNotFoundException because
  entityName is not an actual class name. Hibernate criteria can accept either an
  entity name or a class name. It has been changed to set class name instead of
  entity so that it finds the class in the classloader cache earlier removing contention.

  Note when criteria is used for scrolling, Hibernate's flow is different and it
  expects it to be an entity name, though in this case there's no contention because
  class is resolved by internal caches. This is also covered in the fix as exceptional
  case.

---
M src/org/openbravo/dal/service/OBCriteria.java
M src/org/openbravo/dal/service/OBDal.java
---
(0094452)
caristu (developer)
2017-02-20 09:10

Code Reviewed
(0094534)
hgbot (developer)
2017-02-22 14:15

Repository: erp/devel/pi
Changeset: 302ebfe140555c3c6bf7f49593199ffe644b8566
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Wed Feb 22 14:14:23 2017 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/302ebfe140555c3c6bf7f49593199ffe644b8566 [^]

related with bug 20515: OBCriteria creates contention at JVM

  Same fix for missing createCriteria with alias.

---
M src/org/openbravo/dal/service/OBDal.java
---
(0095189)
hudsonbot (developer)
2017-03-15 20:19

A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/54e102bef53e [^]
Maturity status: Test
(0095203)
hudsonbot (developer)
2017-03-15 20:19

A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/54e102bef53e [^]
Maturity status: Test

- Issue History
Date Modified Username Field Change
2012-05-15 17:18 alostale New Issue
2012-05-15 17:18 alostale Assigned To => alostale
2012-05-15 17:18 alostale Modules => Core
2012-05-15 17:18 alostale Relationship added related to 0020485
2012-05-17 12:08 mtaal Note Added: 0048728
2012-06-01 07:55 alostale Tag Attached: Performance
2012-06-01 07:55 alostale Relationship added duplicate of 0020611
2012-06-01 08:00 alostale Relationship replaced related to 0020611
2012-06-05 15:36 hgbot Checkin
2012-06-05 15:36 hgbot Note Added: 0049621
2012-06-05 15:36 hgbot Checkin
2012-06-05 15:36 hgbot Note Added: 0049623
2012-06-05 15:36 hgbot Checkin
2012-06-05 15:36 hgbot Note Added: 0049624
2012-09-24 12:53 AugustoMauch Note Added: 0052334
2012-09-24 12:53 AugustoMauch Status new => scheduled
2013-01-07 06:47 eintelau Issue Monitored: eintelau
2017-02-15 12:38 alostale File Added: CriteriaVsQuery.java
2017-02-15 12:42 alostale Triggers an Emergency Pack => No
2017-02-15 12:42 alostale Description Updated View Revisions
2017-02-15 12:42 alostale Steps to Reproduce Updated View Revisions
2017-02-15 12:59 alostale File Added: cpu-time.png
2017-02-15 13:00 alostale File Added: lock-monitor.png
2017-02-15 13:03 alostale Description Updated View Revisions
2017-02-15 13:13 alostale Description Updated View Revisions
2017-02-15 13:17 alostale Proposed Solution updated
2017-02-15 14:01 alostale Relationship added related to 0035271
2017-02-16 09:53 alostale Relationship added related to 0020666
2017-02-16 09:54 alostale Summary Slow OBCriteria => OBCriteria creates contention at JVM
2017-02-16 10:25 hgbot Checkin
2017-02-16 10:25 hgbot Note Added: 0094382
2017-02-16 10:25 hgbot Status scheduled => resolved
2017-02-16 10:25 hgbot Resolution open => fixed
2017-02-16 10:25 hgbot Fixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/0e3c102ec91e2102fbdacc049b48986a400809b7 [^]
2017-02-16 10:26 alostale Review Assigned To => caristu
2017-02-20 09:10 caristu Note Added: 0094452
2017-02-20 09:10 caristu Status resolved => closed
2017-02-20 09:10 caristu Fixed in Version => 3.0PR17Q2
2017-02-22 14:15 hgbot Checkin
2017-02-22 14:15 hgbot Note Added: 0094534
2017-03-15 20:19 hudsonbot Checkin
2017-03-15 20:19 hudsonbot Note Added: 0095189
2017-03-15 20:19 hudsonbot Checkin
2017-03-15 20:19 hudsonbot Note Added: 0095203
2017-10-06 10:42 alostale Relationship added related to 0037015


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker