-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Python Support
-
Python Drivers
-
Not Needed
-
Detailed steps to reproduce the problem?
If you call `insert_many()` from two different threads that are being run concurrently, the ObjectId generation will regenerate the random number used for the id each time the threads swap. This ends up spending a lot of cpu time generating random numbers rather than actually inserting documents.
Definition of done: what must be done to consider the task complete?
Swapping threads wouldn't slow down compared to not swapping threads. That is, using a thread pool shouldn't make inserts substantially slower.
The exact Python version used, with patch level:
$ python -c "import sys; print(sys.version)"
3.11.9 (main, Aug 6 2024, 13:17:01) [GCC 13.2.0]
The exact version of PyMongo used, with patch level:
$ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
4.8.0
True
Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.
docker of mongo:latest
The operating system and version (e.g. Windows 7, OSX 10.8, ...)
Ubuntu 24.04
Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)
Security Vulnerabilities
If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here