Reduce server selection and pool lock overhead on the checkout hot path

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Performance
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      PYTHON-5672 eliminates three generator frames from the checkout path. The next bottleneck is lock granularity.

      Topology lock: topology.select_server() holds a single coarse lock for the entire selection loop, serializing every concurrent checkout even when a suitable server is already cached. Replace it with a reader/writer pattern: reads of topology.description hold only a shared read lock; the write lock is acquired only during monitor updates (topology mutations). This is the same approach used in the Java and Go drivers.

      Pool lock merging: _get_conn() }}acquires two back-to-back locks on the fast path ({{operation_count then active_sockets). Merge into one acquire to remove ~50–150 ns per checkout.

      Definition of done

      Locks are optimized, CMAP, SDAM, and unified-format spec tests pass, concurrent throughput under 10+ parallel checkouts improves measurably.

      Pitfalls

      Ensure we are not introducing undo complexity.

            Assignee:
            Unassigned
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: