Thread: [Cgi-session-user] performance enhancement request
Brought to you by:
sherzodr
From: Rhesa R. <pe...@rh...> - 2007-05-14 13:21:47
|
Hi, Gearing up for a big upcoming event, where we expect many millions of new visitors in the space of a few hours, I've been working on making our web app as lean as possible. It quickly became obvious that CGI::Session was choking our database, and the reason for that is that it insists on flushing the session on every single request (to store the new ATIME). That makes any attempt at caching futile, so I've patched my local install to only accept changes to the ATIME once every minute or so. As a result, the load on the master database has dropped dramatically. It now also makes sense to use caching (in the form of CGI::Session::Driver::memcached_mysql, in my case), so reads are spread over many machines. I'd like to see code for this included in the main distribution though, as hacks like this have a tendency to break with upgrades. What I think is needed for this, is to decouple the ATIME code at the end of load(), and put that in its own method for easy overriding. Right now, load() is rather monolithic. Attached is my hack, in case it helps anyone. Rhesa =pod =head1 NAME CGI::Session::LessAtime - Stops flush() on every request =head1 USAGE use CGI::Session; use CGI::Session::LessAtime; # normal session code follows =head1 LIMITATIONS Only works with the default serializer. =cut package CGI::Session::LessAtime; use strict; my $interval = 60; #seconds use CGI::Session; use CGI::Session::Serialize::default; { no strict 'refs'; my $thaw_orig = \&CGI::Session::Serialize::default::thaw; *CGI::Session::Serialize::default::thaw = sub { my $ret = $thaw_orig->(@_); $ret->{__SESSION_ORIG_ATIME} = $ret->{_SESSION_ATIME}; return $ret; }; my $load_orig = \&CGI::Session::load; *CGI::Session::load = sub { my $ret = $load_orig->(@_); if( defined $ret and _elapsed( $ret ) < $interval ) { $ret->_unset_status( CGI::Session::STATUS_MODIFIED ); } return $ret; }; sub _elapsed { my $ret = shift; return $ret->{_DATA}{_SESSION_ATIME} - $ret->{_DATA}{__SESSION_ORIG_ATIME} ; } } 1; |
From: Mark S. <ma...@su...> - 2007-05-21 13:54:07
|
On Mon, 2007-05-14 at 15:21 +0200, Rhesa Rozendaal wrote: > Hi, > > Gearing up for a big upcoming event, where we expect many millions of new > visitors in the space of a few hours, I've been working on making our web app > as lean as possible. Rhesa, I like this idea and would welcome a patch to put update_atime() into its own method. Mark > > It quickly became obvious that CGI::Session was choking our database, and the > reason for that is that it insists on flushing the session on every single > request (to store the new ATIME). That makes any attempt at caching futile, so > I've patched my local install to only accept changes to the ATIME once every > minute or so. As a result, the load on the master database has dropped > dramatically. It now also makes sense to use caching (in the form of > CGI::Session::Driver::memcached_mysql, in my case), so reads are spread over > many machines. > > I'd like to see code for this included in the main distribution though, as > hacks like this have a tendency to break with upgrades. What I think is needed > for this, is to decouple the ATIME code at the end of load(), and put that in > its own method for easy overriding. Right now, load() is rather monolithic. > > Attached is my hack, in case it helps anyone. > > Rhesa > > =pod > > =head1 NAME > > CGI::Session::LessAtime - Stops flush() on every request > > =head1 USAGE > > use CGI::Session; > use CGI::Session::LessAtime; > # normal session code follows > > =head1 LIMITATIONS > > Only works with the default serializer. > > =cut > > package CGI::Session::LessAtime; > > use strict; > my $interval = 60; #seconds > > use CGI::Session; > use CGI::Session::Serialize::default; > > { > no strict 'refs'; > my $thaw_orig = \&CGI::Session::Serialize::default::thaw; > *CGI::Session::Serialize::default::thaw = sub { > my $ret = $thaw_orig->(@_); > $ret->{__SESSION_ORIG_ATIME} = $ret->{_SESSION_ATIME}; > return $ret; > }; > > my $load_orig = \&CGI::Session::load; > *CGI::Session::load = sub { > my $ret = $load_orig->(@_); > > if( defined $ret and _elapsed( $ret ) < $interval ) { > $ret->_unset_status( CGI::Session::STATUS_MODIFIED ); > } > return $ret; > }; > > sub _elapsed { > my $ret = shift; > return > $ret->{_DATA}{_SESSION_ATIME} > - $ret->{_DATA}{__SESSION_ORIG_ATIME} > ; > } > } > > 1; > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Cgi-session-user mailing list > Cgi...@li... > https://lists.sourceforge.net/lists/listinfo/cgi-session-user -- . . . . 1997-2007: Ten Years of Excellence. . . . . . Mark Stosberg Principal Developer ma...@su... Summersault, LLC 765-939-9301 ext 202 database driven websites . . . . . http://www.summersault.com/ . . . . . . . . |