vivarium-collective / vivarium-core

Core Interface and Engine for Vivarium
https://vivarium-core.readthedocs.io/
Apache License 2.0
25 stars 2 forks source link

Create new MongoClient per OS process #218

Closed thalassemia closed 2 years ago

thalassemia commented 2 years ago

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.