John Dickinson said:
> I breifly played around with using Warren Smith's DBConnectionPool class
> on some stuff (I'm surprised he hasn't responded in this thread yet).

I guess I DO usually chime in on these type of discussions, at least
enough for you to wonder why I haven't yet this time:-).  I admit to being
a little weary of discussing this.  I guess I need to write up something
on the Wiki and then just point people to it.  This is a common enough
question that perhaps something should be included in the docs in the next
release of Webware.

Perhaps I could even get an updated version of DBConnectionPool into the
MiscUtils section of the Webware source.  There was someone else recently
that was inquiring about a pooling module and I offered to collaborate
with them on improving DbConnectionPool.  I never did get a response,
however.

> I think you can get his pooling module from the webware sandbox.

Here is the URL:
http://cvs.sourceforge.net/viewcvs.py/webware-sandbox/Sandbox/wsmith323/

> His pooling
> module allows for a separate thread to run and handle some of the
> connection management (old/stale connections). To implement it, I put some
> of the setup in the sitepage (class level and module level). See my
> example below. Anyone please correct me if I'm wrong in my implementation.
>

You're implementation looks OK.  I assume you are calling the .close()
method (to put the conneciton back in the pool) when you are done with the
connection in each request.  The destructor on the connection wrapper will
call .close() if you forget to, but it is good form to call it
explicitely.
I noticed that you have commented out the call to .stopExpiration() in the
destructor for the base servlet.  I would remove it entirely, since I
can't think of a good reason to ever call it, except maybe within a test
suite.

>
> --== sitepage (DBtestpage.py) ==--
> from DbConnectionPool import DbConnectionPool
> from WebKit.Page import Page
>
> #from pyPgSQL import PgSQL as db_mod
> import sys
> import PyIngres as db_mod
>
> maxPoolSize = 10    # 0 or None for unlimited
> dbPool = DbConnectionPool(maxPoolSize, db_mod,
> {'database':'foo','user':'bar'})
> dbPool.startExpiration(expireIntervalSeconds=10, maxIdleSeconds=20,
> maxAgeSeconds=30, aggressiveExpiration=True)
>
> class DBtestpage(Page):
>
>     def __init__(self):
>           global dbPool
>
>           self._dbPool = dbPool
>           Page.__init__(self)
>
>     def getDBPool(self):
>           return self._dbPool
>
>     def writeContent(self):
>           #self.writeln('DBtestpage')
>           self.response().sendRedirect('DBtest.py')
>
>     def __del__(self):
>           self.writeln('in __del__')
>           #self._dbPool.stopExpiration()
>           Page.__del__(self)
>
>
> --== servlet page (DBtest.py) ==--
> from DBtestpage import DBtestpage
>
> class DBtest(DBtestpage):
>     def __init__(self):
>           DBtestpage.__init__(self)
>     def writeContent(self):
>           try:
>               conn = self.getDBPool().getConnection()
>           except:
>               # problem, bail
>               return
>           else:
>               self.writeln('successful.')
>
-- 
Warren Smith
[EMAIL PROTECTED]


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to