Why Pymongo two ways to connect mongodb efficiency difference so much, the principle of science

Source: Internet
Author: User
Tags mongoclient

Recent projects in the use of MongoDB, used to be very useful, but the user on the volume, obviously feel a little slow, why so slow, I began to slowly look for reasons.

Combined with online test scripts and some of my friends ' test results and the results of my own tests, I found that MongoDB is really not that slow, and that's where I wrote it wrong?

I started to find out where in the project code it was different from what was written in the test script, and the result was the way the database was connected, and the project started with the Pymongo recommended Mongoclient (Ip,port), but the test script used connection ( Ip,port), a number of different levels of testing have resulted in the following:

Method

Number

Time

connection

1

0.000314950942993

mongoclient

1

0.000757217407227

connection

10

0.00154709815979

mongoclient

10

0.00501179695129

connection

100000

6.14999890327

mongoclient

100000

27.3278138638

connection

1000000

59.0989689827

Mongoclient

1000000

273.486183882

    • Results analysis

From the results of the above table can be seen, basically mongoclient the connection way to insert data is about 4 times times the connection connection method inserted data, of course, when the amount of data is small may establish a connection and some non-related operations may account for a larger proportion, the more stable later.

    • Questions

1, this let me have a question, pymongo the two ways of the implementation of the principle of how different, resulting in their write efficiency is so much difference?

2, the project of course to adopt a higher connection efficiency method, but now do not know the principle of implementation, the heart is relatively no end, not quite sure is the method of connection is relatively fast, but will not need to manually manage the connection resources, if the operation is too much, will not cause the use of resources

Also ask the gods to recommend some places to solve these problems, or to give a reference to my own study

Why Pymongo two ways to connect MongoDB's efficiency is so much different, to seek the principle of popular science

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.