Remove per-attribute read lock from CompressedSchema decode path#670
Open
vharseko wants to merge 2 commits into
Open
Remove per-attribute read lock from CompressedSchema decode path#670vharseko wants to merge 2 commits into
vharseko wants to merge 2 commits into
Conversation
CompressedSchema.decodeAttribute()/decodeObjectClasses() acquired a ReentrantReadWriteLock read lock for every attribute of every entry read from a backend — 20+ lock acquisitions per bind, hundreds of thousands of CAS operations per second on one contended cache line under load. The lock only guarded reads of the schema and mappings references: the Mappings internals are already concurrent collections. Make both references volatile and read them lock-free. On schema reload the new mappings reference is published before the schema reference, so a reader observing the current schema also observes the mappings rebuilt for it. Mutations (id registration, schema reload) stay serialized on an exclusive lock, with the mappings reference re-read under the lock since a reload may have replaced it. Interleaved A/B under the PR OpenIdentityPlatform#660 bind benchmark scenario shows +1..+22% throughput (avg +11%) and consistently lower latency on an 8-core host.
maximthomas
approved these changes
Jul 2, 2026
This was referenced Jul 2, 2026
Capture the mappings reference once under the exclusive lock and reuse the local for the size calculation and both reload calls. Not required for correctness — mutations are serialized by the same lock — but it makes the reload-from-one-snapshot intent explicit, drops the repeated volatile reads and matches the pattern already used in getAttributeId() and getObjectClassId().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Another BIND/read hot-path serialization point found while profiling after
#660:
CompressedSchema.decodeAttribute()/decodeObjectClasses()acquirea
ReentrantReadWriteLockread lock for every attribute of every entryread from a backend. Decoding one user entry takes K+1 lock acquisitions
(~20+ per bind), i.e. hundreds of thousands of CAS operations per second on
one contended cache line under load. This PR makes the read path lock-free.
Problem
Every decode calls
reloadMappingsIfSchemaChanged(), which took the sharedlock just to compare the schema reference and read the mappings reference:
Read locks do not block each other, but every acquire/release is a CAS on
the RRWL sync word — a cross-core cache-coherency hotspot on the per-backend
singleton (
PersistentCompressedSchema). TheMappingsinternals arealready concurrent collections (
CopyOnWriteArrayListfor the id→elementdecode maps,
ConcurrentHashMapfor the encode maps), so the lock onlyguarded reads of two references.
Change
schemaandmappingsbecomevolatileand are read lock-free on thedecode path. On schema reload the new mappings reference is published
before the schema reference, so a reader that observes the current
schema is guaranteed to observe the mappings rebuilt for it (ids are
stable across rebuilds).
getAttributeId()/getObjectClassId()(encode path) get the samelock-free fast path via the encode
ConcurrentHashMap; registration of anew id stays serialized on the exclusive lock, re-reading the mappings
reference under the lock since a concurrent reload may have replaced it.
ReentrantReadWriteLockis replaced by a singleReentrantLockusedonly by mutators (id registration, schema reload). Behaviour is otherwise
unchanged.
Benchmark
Same harness as #660/#667/#669: packaged server,
jebackend, 5,000 users(
{SSHA}),authratewith 200 persistent connections re-binding as randomusers, JDK 11, 8-core host. Interleaved A/B (old → new → old → new after a
cool-down, warm-up run before each measurement) to control for thermal
drift:
Both rounds favor the lock-free version (avg +11% throughput, lower
latency); variance on the shared 8-core host is high, and as with #667/#669
the structural win is removing a serialization ceiling that grows with core
count.
authrateerrors: 0.Review follow-up (7a290de)
reloadMappingsIfSchemaChanged()now captures the mappings referenceonce under the exclusive lock (
final Mappings oldMappings = mappings;)and reuses the local for the size calculation and both reload calls.
Not required for correctness — all mutations are serialized by the same
lock, so the repeated volatile reads saw one value — but it makes the
reload-from-one-snapshot intent explicit and matches the pattern already
used in
getAttributeId()/getObjectClassId().Testing
mvn -P precommit -pl opendj-server-legacy verifyforModifyOperationTestCase(932),AddOperationTestCase(137),TestDnKeyFormat(30) — entry encode/decode and schema paths:1099 tests, 0 failures — re-run with the same result after the
review follow-up.
Files
opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java