in reply to CGI to Apache::Registry, or to mod_perl

Are you are benchmarking Apache on the first run of the mod_perl program? It only gets faster the second time the program is run by a particular http daemon. If you have many http daemons running, you will have to do many requests before you notice your program suddenly running faster.

Also, you might try reducing the number of print statements in your code. I think that perl's IO system has changed somewhat since I wrote Re: Speeding up commercial Web applications, but I think that the advice there is still good.

There are a few other optimizations that can improve print statements, but the improvements are small. Things to experiment with are:

Another mod_perl optimization is to move as much computation as possible to a BEGIN {} block, so it is only computed during the first run of your code. Similarly, put cleanup code in an END {} block.

It is easy to get confusing answers when profiling mod_perl. I use Time::HiRes and print the profiling information to STDERR. This is tedious but I suspect that the more deluxe profiling modules were not written with mod_perl in mind!

The ultimate test is load testing, which I do with a bunch of lwp GET requests running at the same time. With this I discover other Apache parameters to tune, such as the number of requests to service before restarting the http daemon. These server restarts require perl to reload the modules.

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re: Re: CGI to Apache::Registry, or to mod_perl
by dd-b (Pilgrim) on Jan 17, 2004 at 18:47 UTC

    Thanks for all your help and patience. I think I know what set of things has been going on, and now know where the time is going.

    All of you will, I'm sure, be shocked, just shocked, to learn that inadequately controlled benchmarking is the cause of my confusion. I was using files in a couple of different directories to test against, and the YAML configuration file in one of the directories is 5k bytes, and in the other is 35k bytes. I happen to have switched between them in just the right pattern to make CGI and mod_perl versions perform about the same overall.

    Some Time::HiRes based internal profiling is what finally allowed me to nail it down. I will, however, point out that I'd done some of that for my initial message, the previous thread where I first asked about this. (Sorry, I'm getting a bit overloaded on suggestions to do things I've already said I've done. But doing some *more* of it did resolve the problem, so maybe I shouldn't complain about that particular case anyway!)

    There's no longer a mystery about where the time goes. However, now that I really understand what's going on, the total amount of time taken is still pretty unsatisfactory. Which leads to my next thread, Big config file reading, or cross-process caching mechanism