3

I am using Mongodb as database for project and i am sending 1000 requests per sec to mongodb. I got a observation that the request which are front in queue works faster as compare to request which are last in queue. I am afraid if call to mongodb increase it will consume more time. I think this i can manage using pool connection.If yes let me know how we increased pool size using python.If no suggest me any other alternative

Following are some results to find documents with field snippetid which i had index

Some request which are send early

db.collection.find({'snippetid': '55a0466a414353801e4ff16a'})

Time Taken 0.00563097000122

db.collection.find({'snippetid': '559417cd5217d572fa120a21'})

Time Taken 0.00330901145935

Some request which are last in queue

db.collection.find({'snippetid': '55a4b1d45217d5e7609e19b2'})

Time Taken 1.95499396324

db.collection.find({'snippetid': '55a059d5be98fa09168b63f9'})

Time Taken 1.96221590042

2 Answers 2

9

Hey you can increased pool size in python using pymongo. Syntax

from pymongo import MongoClient
client = MongoClient('host', port, maxPoolSize=200)

For more details check link

Sign up to request clarification or add additional context in comments.

2 Comments

thanx for your answer
3

From the pymongo documentation for MongoClient:

maxPoolSize (optional): The maximum number of connections that the pool will open simultaneously. If this is set, operations will block if there are maxPoolSize outstanding connections from the pool. Defaults to 100. Cannot be 0.

And given the signature:

 pymongo.mongo_client.MongoClient(
     host='localhost', port=27017, document_class=dict,
     tz_aware=False, connect=True, **kwargs)

So adding maxPoolSize with your desired value within that call will set the size of the connection pool.

Note that "nothing is free" and this comes at a clear cost on both the client and server to maintain a large number of connections. With high request loads you might look at alternate processing methods, or at least balancing the load.

1 Comment

thanx for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.