I got 7 packages; whereof I mostly use 2 or maximally 3, an authentication library, a template library and a file handling library. The rest is more oriented to podcasting etc, which is not used in the main script but which performs also poorly.
I am using ApacheBench as tool to measure the speed of my script and I (should) feel ashamed to post this in public but here goes ;) (this all under Apache 1.3 latest release without mod_perl)
The code is written quite "optimized" to the standards which I know of; but those standards might be completely moot. I cannot post the sources of this application because of diverse reasons (whereof one is the size of it entirely).
How can I find out the culprit? How can I mark points for checking the "current" speed with time? how much time does time take? how should I work on this without rewriting the entire thing? is there any "official" way of finding such problems in code?
**UPDATE**
I've found out a "no packagename" makes no difference at all in a normal running cgi script. Which I wonder is: (1) why would I use this call? (2) would such slow down my scripts? (3) why isn't it unloading? Am I already loading all packages or only from the moment I do "use packagename" ?
A normal request to "printenv" which only contains a few lines (the classic)
#!/usr/bin/perl print "Content-type: text/html\n\n"; while (($key, $val) = each %ENV) { print "$key = $val<BR>\n"; }
Document Path: /printenv.cgi Document Length: 903 bytes Concurrency Level: 20 Time taken for tests: 6.514 seconds Complete requests: 1000 Failed requests: 0 Broken pipe errors: 0 Total transferred: 1045086 bytes HTML transferred: 904806 bytes Requests per second: 153.52 #/sec (mean) Time per request: 130.28 ms (mean) Time per request: 6.51 ms (mean, across all concurrent requests) Transfer rate: 160.44 Kbytes/sec receivedThat's my basic; even if I divide this number by any sane number I do not even come close to what I come with the scripts I have written; so here comes (I do not accept tomatoes as reply :D)
Document Path: /podcaster.cgi Document Length: 2755 bytes Concurrency Level: 20 Time taken for tests: 486.796 seconds Complete requests: 1000 Failed requests: 0 Broken pipe errors: 0 Total transferred: 2901000 bytes HTML transferred: 2755000 bytes Requests per second: 2.05 #/sec (mean) Time per request: 9735.92 ms (mean) Time per request: 486.80 ms (mean, across all concurrent requests) Transfer rate: 5.96 Kbytes/sec receivedThis is .. uhm .. 2 requests per second, mean they say; indeed I find it rather cruel...
I can get crueler than that; now you will probably noticing some hallucinations and/or vomiting issues together with a higher heartrate and risk on instant death because of shock; maybe I should warn you to not read further ...
Document Path: /photocaster.cgi Document Length: 41596 bytes Concurrency Level: 20 Time taken for tests: 119.915 seconds Complete requests: 200 Failed requests: 0 Broken pipe errors: 0 Total transferred: 8348546 bytes HTML transferred: 8319200 bytes Requests per second: 1.67 #/sec (mean) Time per request: 11991.50 ms (mean) Time per request: 599.58 ms (mean, across all concurrent requests) Transfer rate: 69.62 Kbytes/sec receivedshocked? .. no? as last but not least, I present to you the uber-worst-statistic you have probably seen in your entire life.
Document Path: /main.cgi Document Length: 12586 bytes Concurrency Level: 20 Time taken for tests: 235.334 seconds Complete requests: 200 Failed requests: 0 Broken pipe errors: 0 Total transferred: 2545200 bytes HTML transferred: 2517200 bytes Requests per second: 0.85 #/sec (mean) Time per request: 23533.40 ms (mean) Time per request: 1176.67 ms (mean, across all concurrent requests) Transfer rate: 10.82 Kbytes/sec received Connnection Times (ms) min mean+/-sd median max Connect: 0 60 420.6 0 2998 Processing: 18598 22893 1714.3 22948 26722 Waiting: 18597 22893 1714.4 22948 26722 Total: 18598 22953 1768.2 22951 26722 Percentage of the requests served within a certain time (ms) 50% 22951 66% 23791 75% 24201 80% 24498 90% 25267 95% 25864 98% 26201 99% 26359 100% 26722 (last request)
In reply to Why can code be so slow? by freakingwildchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |