Re: FAQ 3.19 How can I make my CGI script more efficient?



Purl Gurl wrote:
Brian Wakem wrote:

Purl Gurl wrote:

Gunnar Hjalmarsson wrote:

Purl Gurl wrote:


(snipped)


Serving up pages via cgi is significantly more efficient than static html
pages; increase in Apache speed is amazing. Apache is relieved of parsing
for content such as html versus plaintext, relieved of producing content
headers, relieved of parsing for server side includes, on and on. Apache
runs lots faster.


This is absolute pish-posh.  Apache running all bell and whistles (SSI etc)
will serve static pages *at least* 100 times faster than mod_cgi served
pages, and twice as fast as mod_perl served pages.


If this is not the case on your machine then you have serious config
problems.


I have done much benchmarking on these issues.


Honestly and truly? I believe you are full of mule manure.


URL measured: http://www.purlgurl.net/~callgirl/index.cgi Page speed: 1.89 sec (see details below) Compare to: 2.49 sec (average speed of all our benchmarks)

Page downloading steps (as seen by Microsoft Internet Explorer):

 Seconds   Status   Activity   URL
0.00 Loading Begin Navigation http://www.purlgurl.net/~callgirl/index.cgi
0.00 Loading Begin Download
0.33 Loading End Navigation
1.90 Interactive End Download
1.90 Complete Document Complete

***

URL measured:   http://www.purlgurl.net/~godzilla/index.html
  Page speed:   6.50 sec    (see details below)
  Compare to:   2.49 sec    (average speed of all our benchmarks)

Page downloading steps (as seen by Microsoft Internet Explorer):

 Seconds   Status   Activity   URL
0.00 Loading Begin Navigation http://www.purlgurl.net/~godzilla/index.html
0.03 Loading Begin Download
3.94 Loading End Navigation
6.48 Interactive End Download
6.50 Complete Document Complete


Hold on, you are benchmarking with Internet Explorer? I'm not sure I should diginify that with a response.


OK, 1000 requests, concurrency of 10, SSI's on.

# ab -n 1000 -c 10 www.mysite.co.uk/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/


Benchmarking www.mysite.co.uk (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software: Apache/2.0.52 Server Hostname: www.mysite.co.uk Server Port: 80

Document Path:          /index.html
Document Length:        55080 bytes

Concurrency Level:      10
Time taken for tests:   0.521083 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      55405720 bytes
HTML transferred:       55245240 bytes
Requests per second:    1919.08 [#/sec] (mean)
Time per request:       5.211 [ms] (mean)
Time per request:       0.521 [ms] (mean, across all concurrent requests)
Transfer rate:          103835.67 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     2    4   1.1      5       9
Waiting:        0    3   1.1      3       8
Total:          2    4   1.1      5       9

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      5
  75%      5
  80%      5
  90%      6
  95%      6
  98%      7
  99%      7
 100%      9 (longest request)



Now same test using a mod_perl served page (which uses CGI.pm for what it's worth).


# ab -n 1000 -c 10 www.mysite.co.uk/cgi-bin/index.cgi
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/


Benchmarking www.mysite.co.uk (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software: Apache/2.0.52 Server Hostname: www.mysite.co.uk Server Port: 80

Document Path:          /cgi-bin/index.cgi
Document Length:        16666 bytes

Concurrency Level:      10
Time taken for tests:   0.845462 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      16842618 bytes
HTML transferred:       16699332 bytes
Requests per second:    1182.79 [#/sec] (mean)
Time per request:       8.455 [ms] (mean)
Time per request:       0.845 [ms] (mean, across all concurrent requests)
Transfer rate:          19453.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       3
Processing:     3    7   2.1      8      14
Waiting:        0    7   2.0      7      14
Total:          3    7   2.1      8      15

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      9
  75%      9
  80%      9
  90%     10
  95%     11
  98%     12
  99%     13
 100%     15 (longest request)


Still 1200/second.

Now I can't bench a mod_cgi script on this machine as I no longer run any, but previous benchmarking showed max throughput at about 30 requests/second.

With a bear bones mod_perl scripts I can get 3000/sec, and 5000/sec for a small HTML page.


-- Brian Wakem Email: http://homepage.ntlworld.com/b.wakem/myemail.png .



Relevant Pages

  • Apache/Tomcat Denial Of Service And Information Leakage Vulnerability
    ... mod_jk 1.2 using Apache Jserv Protocol 1.3 ... Tomcat 4.x Server ... A client may connect to the target machine and deliver several requests ... response back over the connection. ...
    (Bugtraq)
  • Re: [PHP] problem with url_fopen on free hosting environment
    ... I just blocked all tcp requests on port 80 and 443 comming from my own outside IP. ... I know it just limits new connections, and I thought this would work out, but it didn't. ... There's also mod_bandwidth for Apache, not included in the aforementioned topic. ... "All information in this email message, including images, attachments, contains confidential and proprietary information of BESTPLACE CORPORATION and should only be used or serves for the intended purpose and should not be copied, used or disclosed to anyone other than the sole recipient of this e-mail message." ...
    (php.general)
  • Re: Thoughts on mod_lisp
    ... >> lisp based server. ... > (which uses sockets to connect to apache) or mod_proxy. ... 0.68 (mean, across all concurrent requests) ...
    (comp.lang.lisp)
  • Re: [Full-disclosure] Apache Illegal Request Handling Possible XSS Vulnerability
    ... So that implies that Apache is being slightly lax in passing arbitrary ... I think that server should have a list of valid requests. ... as request and protocol makes no sense. ... Albion Wharf, 19 Albion Street, Manchester, M1 5LN, England ...
    (Full-Disclosure)
  • [UNIX] Apache/Tomcat Denial of Service and Information Leakage Vulnerability
    ... Beyond Security would like to welcome Tiscali World Online ... Apache has been the most popular web server on the Internet for the ... A client may connect to the target machine and deliver several requests ... and again sends a second response back to mod_jk. ...
    (Securiteam)