[cgiapp] Re: is my app caching db connection ?

Mark Stosberg mark at summersault.com
Mon Jul 28 12:45:11 EDT 2008


> I just write a small C::A script which used C::A::Plugin::DBH,
> I just use $self->dbh_config(dsn, user, pass); in cgiapp_init(),
> and the script runs as fastcgi on apache with C::A::Dispatch,
> 
> but when I use ab to benchmark the script,
> the db connection seems not be cached:
> 
> mysql> show processlist;
> +------+------+-----------+-----------+---------+------+-------+------------------+
> | Id | User | Host | db | Command | Time | State | Info |
> +------+------+-----------+-----------+---------+------+-------+------------------+
> | 2119 | root | localhost | NULL | Query | 0 | NULL | show processlist |
> | 2461 | root | localhost | joke | Sleep | 0 | | NULL |
> +------+------+-----------+-----------+---------+------+-------+------------------+
> 2 rows in set (0.00 sec)
> 
> mysql> show processlist;
> +------+------+-----------+-----------+---------+------+-------+------------------+
> | Id | User | Host | db | Command | Time | State | Info |
> +------+------+-----------+-----------+---------+------+-------+------------------+
> | 2119 | root | localhost | NULL | Query | 0 | NULL | show processlist |
> | 2780 | root | localhost | joke | Sleep | 0 | | NULL |
> +------+------+-----------+-----------+---------+------+-------+------------------+
> 2 rows in set (0.00 sec)
> 
> the different process_id (2461, 2780) means they are two different
> connections ?

I think that's right. 

I'm not a FastCGI user, but it's my understanding that you would need a
variable to be at least package-scoped for it to be share.

If I'm right, then something like this would stay shared:

our $dbh = DBI->connect(...);
$self->dbh_config($dbh);

> and the same question on C::A::plugin::Config::Simple, I use it in
> cgiapp_init() by
> $self->config_file(file_name);
> 
> can this cache the config object ?

Again, I think the same principle applies. You need to find a way to cache
things you wanted shared in package-scoped variables.

(Or perhaps someone who knows better about FastCGI will correct me).

    Mark




More information about the cgiapp mailing list