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!


In reply to Startup cost, CGI performance by dd-b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.