Mod_perl vs Apache::Registry vs CGI

Ranguard on 2002-01-16T14:54:03

Well, having faffed around with the new site for work, it was still putting too much load on the machine (I've seen it spike at upto a load of 20! though the averadge is about 3). So (as was planned) I investigated converting our Apache::Registry search script into a propper mod_perl handle.

Converting Registry to mod_perl handle
First, use Apache::Request instead of CGI.pm, second use Apache::Cookie instead of CGI::Cookie (or CGI.pm's cookie stuff). This alteration was all relativly easy, just change $cgi_query (CGI.pm object) to $r, setting a value in $r is different and also you have to do $r->print() instead of just print.

The cookie stuff took me a while to get, just remember each cookie is an object not a hash! and then all becomes clear.

The results
Just hitting the search (so it shows the default form) is what I based my test on just to get a base feeling for the speed rather than complicate it with DB connections and the like. Here are the results:

Method          Req/sec        time per request
Standard CGI:   3.36     297.56 ms
Apache::Registry:   10.20     98.43 ms
Mod_perl:   73.31     13.64 ms

The jump between CGI and Registry I was expecting and as I am using Template Toolkit I was also expecting a similar (well, double to trebble) jump in performance from Registry to mod_perl. To get 7 times more requests and increase in speed was beyond anything I could have expected.

So, the lession, mod_perl good! Take the time, have a go it can make an amazing difference.


Cool

barbie on 2002-09-27T09:35:46

We've been looking at improving the performance of our authentication modules, having just converted our whole cgi/module suite to mod_perl safe Perl. I haven't had the chance to write any pure mod_perl handlers before, but you've just given me a good reason to start ... cheers :)