Reduce lock contention during concurrent client disconnects - #8533
Reduce lock contention during concurrent client disconnects#8533sciascid wants to merge 4 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. |
Release the server read lock after snapshotting the connection maps, server ID, and requested CID. This avoids holding the server lock while waiting for client locks when the request requires to loop through and inspect a list of clients. Signed-off-by: Daniele Sciascia <daniele@nats.io>
|
@claude review the two additional commits |
|
Claude finished @sciascid's task in 4m 13s —— View job Review of Two Additional Commits
The two additional commits are:
Both are correct and well-targeted. Details below.
|
Connection updates are not sent for the global account, so skip accConnsUpdate when clients are added or removed from it. Signed-off-by: Daniele Sciascia <daniele@nats.io>
f461e3d to
fbb2fff
Compare
Reduce server lock contention by introducing two additional locks:
eventIdsMuto protect event id generationclosedMuto protect the closed connections ring buffer