Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1896

MongoClient hangs for 0.5 seconds on script exit

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      debian 9.9
      python 3.5.3
      pymongo 3.8.0

      Hello,

      • On script exit, MongoClient() hangs for ~0.5 seconds for no apparent reason.
        • Even without any active connection or any operation done.
      How to reproduce }}{{:{{}}

       

      docker run -it --rm debian bash
      #
      apt update
      apt install -y python3-pip
      pip3 install pymongo
      #
      cat /etc/debian_version
        -> 9.9
      python3 -c "import sys; print(sys.version)"
        -> 3.5.3 (default, Sep 27 2018, 17:25:39)
        -> [GCC 6.3.0 20170516]
      python3 -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
        -> 3.8.0
        -> True
      #  
      echo '''
      import sys
      import pymongo
          
      if len(sys.argv) > 1:
          print("MongoClient")
          pymongo.MongoClient(connect=False)
      else:
          print("nothing")
          
      print("end")
      ''' > test.py
      #
      time python3 test.py
        nothing
        end
        -> real    0m0.120s
      time python3 test.py foo
        MongoClient
        end
        -> real    0m0.633s
      
      • on the 1st run (without foo arg), their is not lag between the "end" and the time command output.
      • but, on the 2nd run (with foo arg to trigger MongoClient) their is a distinct lag between the "end" and the time command output.
      • this is the simplest example to reproduce the bug, but :
        • a explicit ".close()" on MongoClient does NOT help.
        • a "connect=True" does NOT help.
        • doing real CRUD operations on a real authenticated mongod/replicaset/mongos does NOT help.
      • When your applicative processing - including mongo auth and CRUD - takes about 200ms, a +500ms is a huge performance loss.
      • I tried to reproduce this bug in php and nodejs but could not :
        • php : 21ms -> 29ms => no loss.
        • nodejs : 48ms -> 107ms => +50ms loss (still huge, but acceptable).

      Any help would be greatly appreciated.

            Assignee:
            ben.warner@mongodb.com Ben Warner (Inactive)
            Reporter:
            clement@compilatio Clement R
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: