Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0037919Openbravo ERPA. Platformpublic2018-02-15 08:542018-03-05 16:39
alostale 
alostale 
normaltrivialhave not tried
closedfixed 
5
 
3.0PR18Q2 
AugustoMauch
No
Core
No
0037919: some contention on session creation, deactivation and check
org.openbravo.erpCommon.security.SessionListener keeps a Set of sessions in current node in order to perform checks for CU. All actions in that set need to be synchronized in order to guarantee thread safety.

This synchronization in cases of very high concurrency causes some contention, specially if CU is reached and existing sessions need to be checked, which is the most expensive action, in this case session creation and deactivation is contained.
Modify org.openbravo.test.system.Sessions test to generate 10K sessions in 10 threads and execute it. Check it takes around 250s to complete.

0 [main] INFO org.openbravo.test.system.Sessions - Starting 10 threads to create 10000 sessions each
200817 [pool-2-thread-7] INFO org.openbravo.test.system.Sessions - Thread finished in 200480 ms
216782 [pool-2-thread-1] INFO org.openbravo.test.system.Sessions - Thread finished in 216447 ms
217398 [pool-2-thread-9] INFO org.openbravo.test.system.Sessions - Thread finished in 217061 ms
227083 [pool-2-thread-3] INFO org.openbravo.test.system.Sessions - Thread finished in 226746 ms
227770 [pool-2-thread-2] INFO org.openbravo.test.system.Sessions - Thread finished in 227433 ms
230525 [pool-2-thread-6] INFO org.openbravo.test.system.Sessions - Thread finished in 230188 ms
233148 [pool-2-thread-8] INFO org.openbravo.test.system.Sessions - Thread finished in 232811 ms
237709 [pool-2-thread-10] INFO org.openbravo.test.system.Sessions - Thread finished in 237372 ms
247972 [pool-2-thread-4] INFO org.openbravo.test.system.Sessions - Thread finished in 247635 ms
251520 [pool-2-thread-5] INFO org.openbravo.test.system.Sessions - Thread finished in 251183 ms
251603 [main] INFO org.openbravo.test.system.Sessions - All finished in 251269 ms
Use a set backed from a ConcurrentHashMap so synchronization does not need to be done by external code, which simplifies the code as well as reduces contention limiting it to internal buckets rather than to the whole object.

After this change time is reduced to 47s:

0 [main] INFO org.openbravo.test.system.Sessions - Starting 10 threads to create 10000 sessions each
45711 [pool-2-thread-6] INFO org.openbravo.test.system.Sessions - Thread finished in 45363 ms
46570 [pool-2-thread-4] INFO org.openbravo.test.system.Sessions - Thread finished in 46222 ms
46573 [pool-2-thread-1] INFO org.openbravo.test.system.Sessions - Thread finished in 46226 ms
46808 [pool-2-thread-2] INFO org.openbravo.test.system.Sessions - Thread finished in 46460 ms
47108 [pool-2-thread-7] INFO org.openbravo.test.system.Sessions - Thread finished in 46759 ms
47138 [pool-2-thread-8] INFO org.openbravo.test.system.Sessions - Thread finished in 46789 ms
47392 [pool-2-thread-9] INFO org.openbravo.test.system.Sessions - Thread finished in 47043 ms
47473 [pool-2-thread-5] INFO org.openbravo.test.system.Sessions - Thread finished in 47125 ms
47764 [pool-2-thread-10] INFO org.openbravo.test.system.Sessions - Thread finished in 47415 ms
47818 [pool-2-thread-3] INFO org.openbravo.test.system.Sessions - Thread finished in 47470 ms
47833 [main] INFO org.openbravo.test.system.Sessions - All finished in 47486 ms
Performance
png 37919-before.png (21,556) 2018-02-15 14:35
https://issues.openbravo.com/file_download.php?file_id=11585&type=bug
png

png 37919-after.png (19,259) 2018-02-15 14:35
https://issues.openbravo.com/file_download.php?file_id=11586&type=bug
png
Issue History
2018-02-15 08:54alostaleNew Issue
2018-02-15 08:54alostaleAssigned To => platform
2018-02-15 08:54alostaleOBNetwork customer => No
2018-02-15 08:54alostaleModules => Core
2018-02-15 08:54alostaleTriggers an Emergency Pack => No
2018-02-15 14:30alostaleSeverityminor => trivial
2018-02-15 14:30alostaleSummarycontention on session creation, deactivation and check => some contention on session creation, deactivation and check
2018-02-15 14:30alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=16707#r16707
2018-02-15 14:30alostaleProposed Solution updated
2018-02-15 14:32alostaleProposed Solution updated
2018-02-15 14:35alostaleFile Added: 37919-before.png
2018-02-15 14:35alostaleFile Added: 37919-after.png
2018-02-15 14:35alostaleTag Attached: Performance
2018-02-15 14:38hgbotCheckin
2018-02-15 14:38hgbotNote Added: 0102437
2018-02-15 14:39alostaleAssigned Toplatform => alostale
2018-02-15 14:39alostaleStatusnew => scheduled
2018-02-15 14:39alostaleStatusscheduled => resolved
2018-02-15 14:39alostaleFixed in SCM revision => ca9d0d95c9b7
2018-02-15 14:39alostaleResolutionopen => fixed
2018-02-15 14:39alostaleReview Assigned To => AugustoMauch
2018-02-22 18:19hudsonbotCheckin
2018-02-22 18:19hudsonbotNote Added: 0102766
2018-03-05 16:39AugustoMauchNote Added: 0102982
2018-03-05 16:39AugustoMauchStatusresolved => closed
2018-03-05 16:39AugustoMauchFixed in Version => 3.0PR18Q2

Notes
(0102437)
hgbot   
2018-02-15 14:38   
Repository: erp/devel/pi
Changeset: ca9d0d95c9b718fd01574d9d0c3d659882b31b2e
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Thu Feb 15 14:37:32 2018 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/ca9d0d95c9b718fd01574d9d0c3d659882b31b2e [^]

fiexed bug 37919: contention on session creation, deactivation and check

  Replaced HashSet that required to be externally synchronized with a Set backed
  with a ConcurrentHashMap which better handles synchronization.

---
M src-test/src/org/openbravo/test/system/Sessions.java
M src/org/openbravo/erpCommon/security/SessionListener.java
---
(0102766)
hudsonbot   
2018-02-22 18: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/980a6ad5bbf5 [^]
Maturity status: Test
(0102982)
AugustoMauch   
2018-03-05 16:39   
Code reviewed and verified