The MongoDB documentation recommends that only a single MongoClient be created per application, taking advantage of connection pooling to reduce latency and the number of new connections (refer to docs). At the same time, PyMongo is not fork-safe and strongly recommends that a new MongoClient be created for each child process. This PR strikes a balance between these guidelines by caching MongoClient instances by PID, only spawning a new instance if running under a new PID.
By creating this pull request, I agree to the Contributor License
Agreement, which is available in CLA.md at the top level of this
repository.
The MongoDB documentation recommends that only a single
MongoClient
be created per application, taking advantage of connection pooling to reduce latency and the number of new connections (refer to docs). At the same time, PyMongo is not fork-safe and strongly recommends that a newMongoClient
be created for each child process. This PR strikes a balance between these guidelines by cachingMongoClient
instances by PID, only spawning a new instance if running under a new PID.By creating this pull request, I agree to the Contributor License Agreement, which is available in
CLA.md
at the top level of this repository.