Menu

connection pooling

Amit Khan
2002-05-29
2012-09-19
  • Amit Khan

    Amit Khan - 2002-05-29

    connection pooling manager is kind of a object responsible for create/manage connection. All connection related request should be routed through the connection pool. Pool manager will keep track on whether a connection is being used by a user or not and will allocate a free connection to serve a request for new connection. To implement the same, we need to know/check whether a connection is free or not. I need some idea, how to identify/find out the same. MySQLDB is not shipped with a connection pool manager - is there any solution available already? 

     
    • Andy Dustman

      Andy Dustman - 2002-06-30

      I have a separate product for pooling objects (not just connection objects) to handle this:

      http://dustman.net/andy/python/Pool

      Example:

      import MySQLdb
      from Pool import Pool, Constructor

      cp = Pool(Constructor(MySQLdb.connect, host="foo", db="blah",...))

      ...
      db = cp.get()
      # use db for awhile
      cp.put(db)
      del db

       
    • sharky

      sharky - 2005-09-09

      Hi,

      I use a web server in python (Snakelets) and I have implemented your example to have a permanent connection to mysql.

      In the web server I can have many webapps and each webapp generates a session for each user that opens a page.

      In the webapp I have:
      cp = Pool(Constructor(MySQLdb.connect, host="foo", db="blah",...))

      In each webapp.session I use:

      when session begins

      db = webapp.cp.get()
      ... # use db

      when session ends

      webapp.cp.put(db)
      del db

      My question: Is there any problem have many sessions using [db = webapp.cp.get() ] ??

      Thanks,
      Helio Pereira
      Sharky @ PTNet

      PS.: Sorry my english :P

       
      • Andy Dustman

        Andy Dustman - 2005-09-09

        There shouldn't be a problem. If the Pool is empty and .get() is called, it just makes a new connection.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.