dd-b has asked for the wisdom of the Perl Monks concerning the following question:
I've been unhappy with my local picture display page routine recently. I just got through revising it considerably, and now I don't like the performance.
The first item of confusion is that I get somewhat different performance numbers depending on how I measure it. (I should mention, since I'm new here, that I've been developing software commercially for 35 years now, and don't think I'm making the really most basic stupid benchmarking mistakes; for example I'm pretty aware of what else is running on the server at the same time).
Using ab (Apache benchmark program) shows it taking about 3.5 seconds to cough up the image page (not including sending the actual image). Running the script standalone (providing environment variables manually to simulate the CGI environment) claims it takes a bit less than 2 seconds (Unix time command). And using Time::HiRes and some embedded code (also running standalone) gives numbers around 3 seconds. This last also gives me a bit of profiling.
First question: I did something "clever" in my Time::HiRes profiling, is it valid?
[snip] BEGIN {$prevtime = time();}; [snip] sub marktime ($) { my $label = shift; my $newtime = time(); my $diff = $newtime - $prevtime; print "Mark $label time $newtime diff $diff\n"; $prevtime = $newtime; } marktime ("Executing");
And then, throughout the later code, put in marktime calls at each point I think might be interesting.
I believe that by putting my first time capture in a BEGIN, I'm capturing all the time spent loading modules (which are all "used" after that BEGIN). I won't get the actual initialization time of the perl executable, though. Is this right?
And when I use the Unix time command and run the script on the command line, what does that measure? That mode gives me the smallest measured time value (elapsed time) of anything I've tried.
Okay, so here are the times measured:
PATH_INFO="/time/galpage" PATH_TRANSLATED="/home/httpd/html/test/galpa +ge" QUERY_STRING="id=Ep850-20011002-036" SCRIPT_NAME="foobar" time t. +cgi Mark Executing time 1074046822.13994 diff 2.13994002342224 Mark YAML read time 1074046822.71538 diff 0.57544207572937 Mark fiddling time 1074046822.71724 diff 0.00185680389404297 Mark order time 1074046822.7257 diff 0.00846314430236816 Mark Comment time 1074046822.72987 diff 0.0041649341583252 Mark stats time 1074046822.73372 diff 0.00384807586669922 [CGI output here] Mark end time 1074046822.73533 diff 0.00161886215209961 1.04user 0.08system 0:01.84elapsed 60%CPU (0avgtext+0avgdata 0maxresid +ent)k 0inputs+0outputs (372major+543minor)pagefaults 0swaps
As you can see, my internal timing reports considerably more time being spent than the Unix time command does. This has me wondering seriously about methodology.
So my figures may be invalid. But if they're valid, then they show that the only thing that takes much time is loading the modules I use. There's measurable time spent loading the info file for the directory (via YAML), and everything else is by comparison trivial. This leaves me few options for improving performance -- except to note in passing that Gallery 1.4, written in PHP, serves up a photo in about half the time.
But I'm not giving up yet. I want to be sure I understand correctly where the time is going, and then I can think about FastCGI, mod_perl, and stuff I guess. I've played with both, but never stuck with either for anything I use regularly.
Pointers, philosophical discussion, corrections to stupid mistakes, and so forth welcomed!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Startup cost, CGI performance
by BrowserUk (Patriarch) on Jan 14, 2004 at 04:04 UTC | |
by b10m (Vicar) on Jan 16, 2004 at 23:51 UTC | |
by BrowserUk (Patriarch) on Jan 17, 2004 at 00:01 UTC | |
|
Re: Startup cost, CGI performance
by perrin (Chancellor) on Jan 14, 2004 at 05:09 UTC | |
by l3nz (Friar) on Jan 14, 2004 at 09:38 UTC | |
by dd-b (Pilgrim) on Jan 14, 2004 at 05:24 UTC | |
by perrin (Chancellor) on Jan 14, 2004 at 15:01 UTC | |
|
Re: Startup cost, CGI performance
by l3nz (Friar) on Jan 14, 2004 at 09:34 UTC | |
by dd-b (Pilgrim) on Jan 14, 2004 at 17:40 UTC | |
|
Re: Startup cost, CGI performance
by dws (Chancellor) on Jan 14, 2004 at 09:55 UTC | |
by dd-b (Pilgrim) on Jan 14, 2004 at 17:55 UTC | |
by dws (Chancellor) on Jan 14, 2004 at 18:53 UTC | |
by dd-b (Pilgrim) on Jan 14, 2004 at 21:26 UTC | |
by dws (Chancellor) on Jan 15, 2004 at 01:08 UTC | |
| |
by zigdon (Deacon) on Jan 14, 2004 at 19:03 UTC | |
|
Re: Startup cost, CGI performance
by bugsbunny (Scribe) on Jan 14, 2004 at 13:35 UTC |