Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:38:18+00:00 2026-06-07T16:38:18+00:00

I have a db = pymongo.Connection() call in Django’s views.py for a simple MongoDB

  • 0

I have a db = pymongo.Connection() call in Django’s views.py for a simple MongoDB connection to store some simple statistics.

What’s the best practice to make it auto support MongoDB connection pooling?

Where do I need to put the end_request() code?

How do I choose the max_pool_size parameter during connection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:38:20+00:00Added an answer on June 7, 2026 at 4:38 pm

    How does connection pooling work in PyMongo?

    Every Connection instance has built-in connection pooling. By default,
    each thread gets its own socket reserved on its first operation. Those
    sockets are held until end_request() is called by that thread.

    Calling end_request() allows the socket to be returned to the pool,
    and to be used by other threads instead of creating a new socket.
    Judicious use of this method is important for applications with many
    threads or with long running threads that make few calls to PyMongo
    operations.

    Alternatively, a Connection created with auto_start_request=False will
    share sockets (safely) among all threads.

    I think it comes down to the type of application you have and how long the requests will hold onto a connection. The idea of calling end_request helps with long running requests holding on to a socket for a long time and causing many sockets to get created. If a single request can release the connection when it no longer needs it, then the socket can be repurposed for other requests.

    If they are fast requests, then I believe the auto_start_request=False works by reusing the socket.

    Ensuring a connection keeps using the same socket means that is will have consistent reads. Think if you made a query but it got delayed, and then immeditely made another query and it used a different socket. This socket manages to respond before the previous. You would have inconsistent data since it does not reflect the previous write.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a problem where after my mongodb connection to mongohq via
I have django installed on my server with pymongo and mongoengine.My django project settings.py
I'm trying to do some benchmarking of Twisted & Tornado with Mongodb. I have
I use: MongoDB 1.6.5 Pymongo 1.9 Python 2.6.6 I have 3 types of daemons.
I need to translate some MySQL to mongodb. I have a MySQL query with
I have gone similar threads like Django persistent database connection and other stuff on
I have strange behaviour in Python/PyMongo. dbh = self.__connection__['test'] first = dbh['test_1'] second =
I have code in Python/PyMongo like ( code should simulate inner join and all
Have a painfully simple blog Post creator, and I'm trying to check if the
I have a PyMongo newbie question: If collection is a PyMongo Collection and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.