You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Brooks <cb...@carescout.com> on 2000/08/21 22:42:27 UTC
Apache::Session and performance question
Hi all,
We have a fairly simple handler responsible for maintaining
state on our web server. Unfortunately, when we activate
it, server performance drops to about 1/10th of what it is
without. After going through the handler and commenting
out parts and benchmarking (rinse, repeat), Apache::Session
appears to be the culprit.
I can't believe that the use of this module should have so
great an effect. We have to be doing something
incorrectly. Any advice would be greatly appreciated.
package Carescout::SessionHandler;
use strict;
use Apache;
use Apache::Session::DBI;
sub handler {
my ( $r ) = shift;
my ( $cookie ) = $r->header_in('Cookie') || undef;
$cookie =~ s/SESSION_ID=(\w*)/$1/o;
my ( %session );
tie %session, 'Apache::Session::DBI', $cookie,
{DataSource => 'dbi:mysql:cs',
UserName => 'nobody',
Password => 'xxxxxxxx'
};
if ( ! $session{ acl } ) {
$session{ acl } = '0';
}
if ( ! $session{ uid } ) {
$session{ uid } = '999999';
}
if ( ! $session{ services } ) {
$session{ services } = '0';
}
$r->subprocess_env( 'SESSION_ID' => $session{
_session_id } );
$r->subprocess_env( 'UID' => $session{ uid } );
$r->subprocess_env( 'ACL' => $session{ acl } );
$r->subprocess_env( 'SERVICES' => $session{ services }
);
my ( $session_cookie ) = "SESSION_ID=$session{
_session_id };path=/;";
tied( %session)->make_modified();
untie %session; # not sure if we need this
$r->header_out("Set-Cookie" => $session_cookie ) if !
$cookie;
}
1;
__END__
Thanks,
Chris
Re: Apache::Session and performance question
Posted by Chris Brooks <cb...@carescout.com>.
Hi, thanks for the reply,
Yes, we are calling the module from http.conf like this:
PerlModule Apache::DBI
PerlRequire /www/perl/scripts/perl-startup.pl
PerlHeaderParserHandler Carescout::SessionHandler
The referenced startup script contains the line:
Apache::DBI->connect_on_init( 'DBI:mysql:cs', 'nobody',
'xxxxxxxx' );
I added
$Apache::DBI::DEBUG = 1;
to the startup file, and it doesn't seem to be creating a
new connection for every request.
Thanks,
Chris
Perrin Harkins wrote:
> On Mon, 21 Aug 2000, Chris Brooks wrote:
> > We have a fairly simple handler responsible for maintaining
> > state on our web server. Unfortunately, when we activate
> > it, server performance drops to about 1/10th of what it is
> > without. After going through the handler and commenting
> > out parts and benchmarking (rinse, repeat), Apache::Session
> > appears to be the culprit.
> >
> > I can't believe that the use of this module should have so
> > great an effect. We have to be doing something
> > incorrectly. Any advice would be greatly appreciated.
>
> You are using Apache::DBI, right?
>
> Going to the database on every single request is going to be
> expensive. If the rest of your application doesn't normally hit the
> database it makes sense for this to have a significant impact.
>
> - Perrin
--
Chris Brooks
Director of Technology
CareScout.com
phone: (781) 431-7033 x 342
Re: Apache::Session and performance question
Posted by Perrin Harkins <pe...@primenet.com>.
On Mon, 21 Aug 2000, Chris Brooks wrote:
> We have a fairly simple handler responsible for maintaining
> state on our web server. Unfortunately, when we activate
> it, server performance drops to about 1/10th of what it is
> without. After going through the handler and commenting
> out parts and benchmarking (rinse, repeat), Apache::Session
> appears to be the culprit.
>
> I can't believe that the use of this module should have so
> great an effect. We have to be doing something
> incorrectly. Any advice would be greatly appreciated.
You are using Apache::DBI, right?
Going to the database on every single request is going to be
expensive. If the rest of your application doesn't normally hit the
database it makes sense for this to have a significant impact.
- Perrin