Open
Description
It seems strange to me that Mongomock is so slow, compared to a real MongoDB (more than 200 times!), when doing bulk inserts.
Is this known/expected? Is there some workaround?
USE_MOCK=False : saved 2000 objects in 0.145 secs (0.072 msecs/obj)
USE_MOCK=True : saved 2000 objects in 30.716 secs (15.358 msecs/obj)
Things get worse as length increases
USE_MOCK=False : saved 5000 objects in 0.222 secs (0.044 msecs/obj)
USE_MOCK=True : saved 5000 objects in 176.310 secs (35.262 msecs/obj)
My code below.
Using mongomock 3.18.0, mongoengine 0.19.1, Python 3.7
from mongoengine import connect, StringField, Document
import time
class DataSample(Document):
code = StringField(required=True, unique=True)
desc = StringField()
USE_MOCK = False
COUNT = 2000
MOCK_URL = "mongomock://localhost"
MONGO_URL = "mongodb://mongodb"
connect("test", host=MOCK_URL if USE_MOCK else MONGO_URL)
DataSample.drop_collection()
objs = [DataSample(code="CODE" + str(n), desc="blahblh") for n in range(COUNT)]
start = time.time()
DataSample.objects.insert(objs, load_bulk=False)
secs = (time.time() - start)
print(f"USE_MOCK={USE_MOCK} : saved {COUNT} objects in {secs:.3f} secs ({1000*secs/COUNT:.3f} msecs/obj)")