[Israel.pm] Apache::SessionManager too "expensive"? [Or: better session management]
yuval at windax.com
Sun May 2 02:07:05 PDT 2004
In my current project I am using mod_perl handlers with Template Toolkit
(which is new to me but I manage to work with it pretty well).
I was looking for the ways people use TT with sessions on google and
I used Mason a lot [I "blame" Reuven for that] and it has
MasonX::Request::WithApacheSession which works well.
To be honest, I usually didn't focus about performance but it didn't
seem to slow things down in a serious way (I might be wrong, again, I
didn't really benchmarked every change I made).
Sometimes there are things I don't like to pay attention to, like Sessions.
So Apache::SessionManager seemed like one of these things that you can
add easily and just work.
The current project doesn't need to run really fast and serve the max
req. per second, but it does need to be fast and resource friendly (so
one day it could serve the max requests per second).
Keeping that in mind, I read all of Stas Beckman's articles on Perl.com,
Practical mod_perl, etc and it helped to keep everything shared.
Even though it does eat a lot of memory, most of it is shared, and I
managed to set the MaxRequestsPerChild to an amount that doesn't make
apache kill its childs (sounds brutal) all the time, but won't give the
process enough time to get its memory dirty.
After that, I still didn't get the performance I was looking for.
I got ~30 requests per second on a rather simple page - I really didn't
know where the bottleneck is.
I tried cursing mod_perl (but it's really fast!), TT, apache, my
Now, TT and DB access using Class::DBI really slow things down but I
knew about it in advance and it really makes development time faster,
and it shouldn't be that slow!
After my cursing session, I just commented the Apache::SessionManager
out of my httpd.conf and I got around 110 requests per second...
And that is on a very slow computer (Celeron 1100Mhz, 256MB SDRAM -
slow). Should run faster on our servers.
Still slow, but fast enough for this project for the next year or two
(probably even forever).
Pages with a lot of DB action, or graph plotting are much slower,
naturally. Can't do much about it and the users will have to understand :)
Ok, sorry for typing too much - I'll get to the real question(s):
Why is Apache::SessionManager so slow???
I tested it using File and MySQL to store sessions. File is faster but
Using SharedMem didn't work but I didn't care enough to investigate - I
was pretty depressed from the results :)
I also didn't Apache::SmallProf-ed it but maybe I should...
Would writing my own handler for sessions (either file or database,
shared memory is too expensive in my opinion, unless it shows a big
performance boost) be any faster, or is it generally a slow procedure?
I didn't want to waste my time before I ask.
I must use sessions because I must know what user is using the system,
what pages he's allowed to see, generate personalized menus, etc.
I can live with the fact that it's slow, but I must choose the optimal tool.
I know I chose some slow tools (TT [using the same object and XS stash,
should be faster], Class::DBI, Sessions in general) but it seemed to
make development time so much faster.
Class::DBI made me write only a few SQL queries (outside my code but
inside the classes themselves) and it made everything so much better.
I never noticed that writing SQL and all the DB[I] stuff took much time...
More information about the Perl