Thursday, December 29, 2016

Re: User model not using persistent DB connection?

I'm actually already setting CONN_MAX_AGE to None on a connection pool.  The rest of the queries in the view are using the persistent connection pools.

It's only this specific request.user object that keeps creating a new connection instead of using the persistent connection for some reason.

-bobby

On Dec 29, 2016, at 4:16 PM, James Bennett <ubernostrum@gmail.com> wrote:

See the documentation for details:


Also, generally speaking maintaining a connection pool has been seen as out of scope for Django itself, and most people use a standalone connection pooler (such as pgpool for Postgres).

On Thu, Dec 29, 2016 at 1:13 PM, Bobby Mozumder <bmozumder@gmail.com> wrote:
Hi,

It seems Django doesn't use a persistent DB connection whenever I use the Request.User object.

I always get a signal saying a new DB connection occurs when I call the object.

For example:

class MyView(DetailView):
    def get(self, request, slug):
        print(request.user) # <--- Boom, new database connection signal is sent here.
        # continue processing view
pass

Is that by design?  Or is it an error?  

I'd like it to use the same persistent DB connection across all requests. 

I'm looking through the Django source (auth & sessions backend) and can't find where the DB connection is happening.  I haven't touched the User models at all, although I do have a DB connection receiver that runs prepared statements when the app starts - it's where I found this.  

Any info on this is appreciated, & happy Holidays!

-bobby

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/A56E8EB4-EE0A-477F-B8DD-F39AA43F71EB%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL13Cg8FmJRC%2Br9VoKoa3R4o_wURMc6kJGQGUB_WG5NJgcZEQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment