2

I work on a benchmark between pymongo and rethinkdb, to compare the time took for insertions.

However this is what I found :

enter image description here

for one-by-one insertions.


def chronometre_rethink_insert_one(data, nblines):
    avant = time()
    for i in data[:nblines]:
        r.table('test_table').insert(dict(zip(names, i))).run()
    return time()-avant


def chronometre_mongo_insert_one(data, nblines):
    avant = time()
    for i in data[:nblines]:
        db.test_table.insert_one(dict(zip(names, i)))
    return time()-avant

I think that the fact that takes mongo is nearly constant is weird. So I wonder maybe pymongo doesn't insert the data whenever I insert it, but rethinkdb yes, as I call run() on all operations ?

If so, how should I have comparable results ?

Ezriel_S
  • 248
  • 3
  • 11
  • pymongo is synchronous unlike its javascript counter part. here is the source: https://gist.github.com/anand2312/840aeb3e98c3d7dbb3db8b757c1a7ace#:~:text=pymongo%20is%20synchronous%2C%20i.e%20it%20is%20blocking%2C%20and%20will%20block%20the%20execution%20of%20your%20asynchronous%20program%20for%20the%20time%20that%20it%20is%20talking%20to%20the%20database. – Savannah Madison Jun 09 '22 at 06:36

2 Answers2

0

Is PyMongo asyncronous?

According to their documentation (https://pymongo.readthedocs.io/en/stable/faq.html), PyMongo fully supports Gevent: So yes, if implemented correctly, PyMongo is able to use an asynchronous framework like Gevent.

Details on how what Gevent is, or how to implement it in your example code:

J. M. Arnold
  • 6,261
  • 3
  • 20
  • 38
  • I understand that we can have asynchronous pymongo with gevent. But without it, is it the case ? – Ezriel_S Dec 20 '20 at 13:35
  • @Ezriel_S Maybe it's me, but the way you phrased your question could (or in fact it did) lead to confusion. Anyhow, I'm glad that you found a solution to your problem! – J. M. Arnold Dec 20 '20 at 14:50
0

It's turn out that I can manage it doing :

client = MongoClient(port=27017, fsync=True)

(adding the fsync), as it "Force the database to fsync all files before returning" (https://api.mongodb.com/python/2.0/api/pymongo/connection.html).

This done, I have result that makes more sense:

enter image description here

Ezriel_S
  • 248
  • 3
  • 11