Re: Connection pooling and with statement

From: Julian <tempura(at)internode(dot)on(dot)net>
To: psycopg(at)postgresql(dot)org
Subject: Re: Connection pooling and with statement
Date: 2013-08-23 14:19:58
Message-ID: 52176F8E.1070405@internode.on.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hi Frank,
Application level connection pooling isn't a bad thing and can bring
some performance improvements in combination with a general connection
pool (pgpool).
Depending on what framework you are using, and how it is setup, it is
possible to share the connection pool between threads, what wsgi
framework are you using? (if any).

regards, Jules.
On 23/08/13 20:03, Frank Broniewski wrote:
> Hi,
>
> I want to use psycopg2 in a WSGI environment. There you can have a
> (configurable) number of processes and threads created that would be
> accessing the database. Now I wonder what might be the best practice
> to implement the pool. I don't think it is practicable to create the
> pool in the WSGI application since this would create a number of pools
> for each process and/or threads.
>
> Or is the pool class simply not suitable for such a task?
>
> Another question that occured to me is how I use the with statement
> with the pool class:
>
> I can do:
> with pool.getconn() as conn:
> with conn.cursor() as cursor:
> # do stuff
>
> Where do I need to call pool.putconn(conn)? How does the with
> statement affect the connection? Is the with statement suitable for
> connection pooling at all?
>
> Many thanks,
>
> Frank
>
>

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Frank Broniewski 2013-08-23 14:45:02 Re: Connection pooling and with statement
Previous Message Samuel PHAN 2013-08-23 11:58:10 Re: Connection pooling and with statement