Investigate ways to improve performance of small read operations

XMLWordPrintableJSON

    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Running a simple command like database.command('ping') shows that about 35% of the time is spent in acquiring a server and a connection. This limits the ability to use the driver for things like throughput tests.

      I created this gist to demonstrate the overhead.

      Before patching client._select_server, I see the following times for 10000 pings:

      command: 1.12
      _command: 0.77

      After patching client._select_server, I see:

      command: 0.86
      _command: 0.77

      I then ran cProfile against 100000 iterations of the non-patched command call to verify where the time was spent. _select_server took 15% of the runtime and checking out a connection took about 20% of the runtime, while db._command was 65% of the runtime.

      We could consider adding an API to get a connection object and then provide it to calls for cases where there is a known topology and a single thread.

      Definition of done

      Investigate whether improvements could be made to idle time for small reads, or if we can/should create an API to use an explicit connection object.

      Pitfalls

      We want to ensure that we remain spec-compliant and thread safe.

        1. ping_test_v2.py
          1 kB
        2. Screenshot 2025-06-09 at 10.43.06 AM.png
          Screenshot 2025-06-09 at 10.43.06 AM.png
          8 kB
        3. Screenshot 2025-06-09 at 10.43.37 AM.png
          Screenshot 2025-06-09 at 10.43.37 AM.png
          9 kB
        4. Screenshot 2025-06-09 at 3.41.12 PM.png
          Screenshot 2025-06-09 at 3.41.12 PM.png
          98 kB
        5. Screenshot 2025-06-09 at 3.41.45 PM.png
          Screenshot 2025-06-09 at 3.41.45 PM.png
          123 kB
        6. profile.svg
          41 kB
        7. single-profiled.svg
          168 kB
        8. threaded-profiled.svg
          88 kB

              Assignee:
              Noah Stapp
              Reporter:
              Steve Silvester
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated: