Use LongAdder for LDAPStatistics counters#678
Open
vharseko wants to merge 1 commit into
Open
Conversation
The statistics counters are shared by every connection of a handler and updated 7-9 times per operation (message read/written, per-type request and response counters, operation monitoring count/time, bytes counters). With AtomicLong all worker threads CAS the same few cache lines on every LDAP message — the same shared-hot-line pattern removed elsewhere on the hot path. Switch to LongAdder: updates go to striped cells, and the cost moves to reads, which only happen when cn=monitor data is requested. Public getters still return long (sum()); clearStatistics() uses reset(), which has the same non-atomic-under-concurrency semantics the previous set(0) had. Monitor data now passes explicit sum() values.
maximthomas
approved these changes
Jul 3, 2026
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
Part of the bind/compare hot-path series (#660, #667–#670, #672, #674): the
last shared-hot-cache-line point identified by both profiling passes.
LDAPStatisticsis a single instance shared by every connection of aconnection handler (
keep-statsis on by default), and its counters areupdated 7–9 times per operation of any type:
updateMessageRead:messagesRead,operationsInitiated, per-typerequest counter;
updateMessageWritten:messagesWritten, per-type response counter,operationsCompleted;updateOperationMonitoringData: per-type operation count + resident time;updateBytesRead/updateBytesWritten.With
AtomicLongevery worker thread CAS-es the same few cache lines onevery LDAP message — the same pattern removed from
AuthenticatedUsers(#660), the password schemes (#667),
getDefaultPasswordPolicy(#669),CompressedSchema(#670) andAciList(#674).Change
All 51 counters become
final LongAdder: updates useincrement()/add()(striped cells, no shared CAS under contention), reads usesum()and only happen whencn=monitordata is requested;clearStatistics()usesreset(), which has the samenon-atomic-under-concurrent-writes semantics the previous
set(0)had.Public getter signatures are unchanged (
long).getMonitorData()passes explicit
sum()values instead of live counter objects.Performance note
Honest caveat, as with the rest of the series: on the 8-core benchmark
host the effect is not locally measurable — an earlier A/B with
keep-stats:false(removing the counters entirely) was within noise at~40k ops/s. The value is structural: LongAdder removes ~7–9 shared-line
CAS per operation for every operation type, a ceiling that grows with
core count, at the cost of slower reads on the rarely-used monitoring
path — exactly the trade-off LongAdder is designed for.
Testing
mvn -P precommit -pl opendj-server-legacy verifyforCompareOperationTestCase(37),SearchOperationTestCase(75),AbandonOperationTestCase(30),TestLDAPConnectionHandler(3) — thesesuites assert exact counter values through the public getters:
145 tests, 0 failures.
Files
opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPStatistics.java