Reduce lock contention during concurrent client disconnects - #8533
Reduce lock contention during concurrent client disconnects#8533sciascid wants to merge 2 commits into
Conversation
Protect event ID generation with a dedicated mutex. This allows accountDisconnectEvent to check whether events are enabled under the server read lock, then generate the event ID without holding the server lock. This avoids serializing concurrent disconnects on the server write lock. Apply the same pattern to all methods that generate event IDs. Signed-off-by: Daniele Sciascia <daniele@nats.io>
Protect the closed connection ring buffer with a dedicated mutex instead of the server lock. This allows saveClosedClient to record closed connections concurrently with closeConnection for the server lock. Signed-off-by: Daniele Sciascia <daniele@nats.io>
|
@claude review |
|
Claude finished @sciascid's task in 3m 54s —— View job Code Review
Overall this is a clean, well-reasoned change that correctly reduces server lock contention during high-frequency client disconnect events. The lock ordering is documented and respected throughout. SummaryThe PR introduces two new fine-grained mutexes to reduce contention on the server's main
This is consistent with how Correctness
The switch from TOCTOU window between check and send After
This acquires
The OCSP event functions correctly capture
Read-only accessors ( Lock ordering documentation ( Both new orderings are correctly described: Tests
The tests now call
Correctly updated to use Nits / suggestionsNone that would block merging. The change is straightforward and well-scoped. |
Reduce server lock contention by introducing two additional locks:
eventIdsMuto protect event id generationclosedMuto protect the closed connections ring buffer