[JAVA-509] ClassMap synchronization is a major source of contention Created: 24/Jan/12 Updated: 18/Jun/12 Resolved: 10/Mar/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Performance |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | 2.8.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Jed Wesley-Smith | Assignee: | Brendan W. McAdams |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
https://github.com/mongodb/mongo-java-driver/blob/master/src/main/org/bson/BSON.java |
||
| Description |
|
Synchronization in the ClassMap class is the number one performance issue in our performance tests - specifically, in BSON.applyDecodingHooks(Object) The problem is that this lock is acquired repeatedly by any thread that is decoding elements, leading to a comb pattern of acquisitions and almost certainly not only guaranteeing contention but a moiré pattern of it leading to heavy switching overhead. A better strategy would be a CopyOnWriteMap. We have an Apache licensed CopyOnWriteMap impl if required. |
| Comments |
| Comment by Jeffrey Yemin [ 18/Jun/12 ] |
|
Closing for 2.8.0 release. |
| Comment by Jeffrey Yemin [ 10/Mar/12 ] |
|
Pull requests merged in to master |
| Comment by Brendan W. McAdams [ 31/Jan/12 ] |
|
A fix for this issue has been merged in a branch as part of Pull Request 57 ( https://github.com/mongodb/mongo-java-driver/pull/57 ). We are working on finishing evaluating it before a final merge to master. |
| Comment by Jed Wesley-Smith [ 24/Jan/12 ] |
|
The applyDecodingHooks method is not properly threadsafe anyway, as it is possible to racily set _encodeHooks or _decodeHooks before the associated map.put completes, neither update is safely published, and the _decodingHooks.size() call is not atomic with the decodingHooks.get(o.getClass()). |