[cgiapp] use persisten instance of cgiapp with cgi::fast?
Mark Fuller
azfuller at gmail.com
Mon Jul 19 11:44:59 EDT 2010
On Mon, Jul 19, 2010 at 8:29 AM, Dietrich Streifert
<dietrich.streifert at visionet.de> wrote:
>
> That is what I'm actually doing. I use dbh->ping() to test if the
> connection is still active and reconnect to the db if needed.
If you're using the class variable to store your DB handle, what was
your concern with performance? (I.e., it sounds like you're doing it
right.).
BTW: The ping method is slightly different than what I described. The
difference could be important if you're obsessed with performance.
If you ping, you're doing that before the DB operation. In most cases,
the connection is fine, so there's no reason to ping. It's a wasted
operation. You should really concerned with exception handling.
Since all DB operations should be wrapped in an eval to catch
unexpected DB errors, you can just use that to trap the non-connected
state on the first operation. Then you're not pinging all the time.
And, you'll catch (and retry) problems which ping won't catch.
I've had zombie connections that appeared to be alive with ping, but
failed. In some cases they hung indefinitely even though ping returned
immediately.
That's probably overkill for most people. But, if you get into DB
lazy-connecting and error-handling, I think it naturally leads to what
I described. It doesn't require any extra processing because you
should use eval anyway. It's just using to catch everything -- even
when a reconnect is needed. (I.e., when even the first connection is
needed.).
Mark
More information about the cgiapp
mailing list