Pymongo significantly slower than mongo shell?

独自空忆成欢 提交于 2019-12-22 08:44:20

问题


I'm relatively new to mongodb, and having a performance problem in pymongo. I have a collection that's 50 GBs (uncompressed) 20 GBs (compressed via WiredTiger) with about 39 million documents. Querying it over indexed fields gives a result that's about 125,000 documents and 150 MBs uncompressed. When I do the following in the mongo shell, it takes about a second.

var result = db.my_collection.find(my_query).toArray()

However, when I do the same thing in pymongo, it takes over 7 seconds.

db = pymongo.MongoClient()['my_db']
result = list(db['my_collection'].find(my_query)) 

Some extra info:

  • I'm using Ubuntu 14.04, python 2.7.6, pymongo 3.2, and mongo 3.2.

  • I think my pymongo is configured to use C because I installed python-dev and both pymongo.has_c() and bson.has_c() show True.

  • Everything is run locally.

I find it hard to believe that pymongo is 7x slower than the mongo shell. What am I missing?

来源:https://stackoverflow.com/questions/35140183/pymongo-significantly-slower-than-mongo-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!