DBI and mod_ruby

working on a cgi app and i’m using a module with a module varaible (@@) to
persist a DBI connection across http requests.

now, i had been opening and closing the connection with each request, but that
is obviously overhead that i don’t need. i should be able to put the
peristance that mod_ruby allows to good use.

but here’s the thing i’m not sure about. if my user dosen’t logout properly
then i have this open connection to the database just hanging about. how do i
close it? will it close itself after a long enough time out period? is it a
big deal to have a semi-eternal connection to the database?

thanks for any help,
transami

Tom Sawyer wrote:

working on a cgi app and i’m using a module with a module varaible (@@) to
persist a DBI connection across http requests.

now, i had been opening and closing the connection with each request, but that
is obviously overhead that i don’t need. i should be able to put the
peristance that mod_ruby allows to good use.

I’m not sure if this is wise.

Correct me if I’m wrong, but mod_ruby, like any apache mod, is running
in-process and as such, it’s behaviour depends on the apache process.

Since Apache 1.3(with the exception of the NT port perhaps) is a forking
server, then every server child is basicly has a seperate Ruby
enviroment(althought initially shared due to copy-on-write mechanism).

So I assume modifying the module variable as done in one apache instance
shall not affect the others, that can be potentially a source of trouble
perhaps.

If you wish to have real persistence, DB Pools etc perhaps you should
consider writing it as FastCGI.

Nevertheless it is very much possible all I said here is total nonsense,
and soon I’m gonna be flooded with flames and RTFM style messages, but I
hope that is not the case:-)

Idan

thanks, Idan, for the word of caution, though i gave it a go anyway. was very
careful about it (i think). yet i applied it “across the board” such that i’m
using ||= on everything that could make suitable use of persistence, which
amounts to about three things: the database connection, meta information
about the database connection, and a session hash.

and guess what? my app speed up many times over! it blazes now!!! what would
take a second or two before now takes practically no time at all. honestly i
am astonished by the speed up. amazing. really, i just can’t get over it. i
just pray that i don’t run into a catch. but so far so good.

i’ve bundled up my work on all this into a single library to make it easy to
use, and will realease it soon if anyone’s interested. more details to
follow…

-transami

Quite interested. In fact, I’m dealing with a question regarding
connetcion pooling too right now, and since my Ruby experience is a
month or so, I’m very shy on “go and do it” :slight_smile:

···

Tom Sawyer transami@transami.net wrote:

i’ve bundled up my work on all this into a single library to make it
easy to use, and will realease it soon if anyone’s interested. more
details to follow…


---- WBR, Michael Shigorin mike@altlinux.ru
------ Linux.Kiev http://www.linux.kiev.ua/