[CDRIVER-4113] Reduce contention on multithreaded session pool Created: 03/Aug/21  Updated: 28/Oct/23  Resolved: 13/Sep/21

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.20.0

Type: Improvement Priority: Unknown
Reporter: Colby Pike Assignee: Colby Pike
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-4124 Clean Up Internal Atomic APIs Closed
Epic Link: Improve multi-threaded perf

 Description   

The session_pool in mongoc_topology_t is shared between threads and guarded by mongoc_topology_t::mutex, which is also locked by numerous other operations.

When a session is requested from the pool, the requesting thread will lock the mutex and loop through every entry in the pool and remove sessions that are alive past their timeout. This can extremely produce latency as the pool grows. Because the same mutex is shared by multiple (some unrelated) operations, this operation blocks almost all clients.

The process of dropping expired sessions need not be performed every single time we want a session from the pool, and holding the lock while performing this garbage collection is extremely detrimental.



 Comments   
Comment by Githook User [ 13/Sep/21 ]

Author:

{'name': 'vector-of-bool', 'email': 'vectorofbool@gmail.com', 'username': 'vector-of-bool'}

Message: CDRIVER-4113: Thread-safe pool for server session objects (#847)

  • CXX-4113: Thread-safe pool for server session objects
  • Remove unused node pointers on server sessions
  • Track pool size, and don't loop while holding the lock to clear
  • Cleanup and some redesign of pool API
  • Declare special pool for server sessions
  • Mention the LIFO nature of the thread-pool, and the non-conformance of the 'push' operation
  • auditing the pool is compile-time optional
Generated at Wed Feb 07 21:19:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.