Database connection caching

Discussion in 'Python' started by lbolognini@gmail.com, Mar 18, 2005.

  1. Guest

    Hi all,

    is there an alternative way of:

    - create a connection object
    - open the connection
    - close the connection

    every time one has to run a query.

    I assume that big sites do something to prevent the performance hit
    given by these operations, don't they?

    Would you kindly point me to some examples of good practices in this
    sense beside http://www.danga.com/words/2004_oscon/oscon2004.pdf ?

    Thanks,
    Lorenzo
    , Mar 18, 2005
    #1
    1. Advertising

  2. Swaroop C H Guest

    On 18 Mar 2005 04:52:03 -0800,
    <> wrote:
    > Hi all,
    >
    > is there an alternative way of:
    >
    > - create a connection object
    > - open the connection
    > - close the connection
    >
    > every time one has to run a query.


    Why not use cursor objects with a single connection object?

    You can have any number of cursor objects and can run with a single
    connection object

    A good introduction is at http://www.amk.ca/python/writing/DB-API.html

    Regards,
    --
    Swaroop C H
    Blog: http://www.swaroopch.info
    Book: http://www.byteofpython.info
    Swaroop C H, Mar 18, 2005
    #2
    1. Advertising

  3. Lorenzo> is there an alternative way of:

    Lorenzo> - create a connection object
    Lorenzo> - open the connection
    Lorenzo> - close the connection

    Lorenzo> every time one has to run a query.

    Sure, create a Queue.Queue object and stuff a number of connections into
    it. When you want a connection call the queue's .get() method. When you're
    done with it .put() it back. This has the other nice feature that a program
    with a large number of threads can't overwhelm your database.

    Skip
    Skip Montanaro, Mar 18, 2005
    #3
  4. On 18 Mar 2005 04:52:03 -0800,
    <> wrote:
    > is there an alternative way of:
    >
    > - create a connection object
    > - open the connection
    > - close the connection
    >
    > every time one has to run a query.


    It's actually morte like:

    create connection
    create cursor
    execute SQL
    process cursor
    close cursor
    close connection

    The bit that you can avoid it the creation of the connection - that's
    an intensive process. If your system is single threaded, or if it's a
    very small app, you can just create a single open connection and keep
    using that. I usually find that I need a pool of open connections,
    though.

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
    Simon Brunning, Mar 18, 2005
    #4
  5. wrote:

    > Hi all,
    >
    > is there an alternative way of:
    >
    > - create a connection object
    > - open the connection
    > - close the connection


    psycopg, a Postgresql database adapter does connection pooling
    automatically

    http://initd.org/projects/psycopg1

    Most Zope database adapters also have implicit
    connection pooling.

    Istvan.
    Istvan Albert, Mar 18, 2005
    #5
  6. Guest

    Thanks everybody for their replies.

    Lorenzo
    , Mar 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    407
  2. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    788
    Troy Simpson
    Jan 19, 2004
  3. Mythran
    Replies:
    5
    Views:
    4,942
    Mythran
    Oct 5, 2005
  4. JimLad
    Replies:
    3
    Views:
    915
    JimLad
    Jan 21, 2010
  5. Steven Hansen

    Capistrano Connection Caching Question

    Steven Hansen, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    112
    Steven Hansen
    Nov 30, 2006
Loading...

Share This Page