用C写的CGI程序和在mod_perl环境下运行的Perl程序,真的有这么大的差距吗?
这是我写的两个测试程序,运行在同一个目录下,这个目录配置了mod_perl。C程序这样编译的gcc -o hello.cgi hello.c,然后用Apache的ab测试,结果大家可能看到C程序的执行效率要慢得多,请大侠指教,这个结论是否正确?谢谢!
# more perl.pl
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "Hello!";
# /server/apache/bin/ab -n100 -c10 'http://www.xxx.com/perl.pl'
This is ApacheBench, Version 1.3d <$Revision: 1.58 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2001 The Apache Group, http://www.apache.org/
Benchmarking newchems.edge-china.com (be patient).....done
Server Software: Apache/1.3.22
Server Hostname: newchems.edge-china.com
Server Port: 80
Document Path: /f/perl.pl
Document Length: 283 bytes
Concurrency Level: 10
Time taken for tests: 0.180 seconds
Complete requests: 100
Failed requests: 0
Broken pipe errors: 0
Non-2xx responses: 104
Total transferred: 48256 bytes
HTML transferred: 29432 bytes
Requests per second: 555.56 [#/sec] (mean)
Time per request: 18.00 [ms] (mean)
Time per request: 1.80 [ms] (mean, across all concurrent requests)
Transfer rate: 268.09 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 1.7 4 10
Processing: 11 12 1.3 11 15
Waiting: 6 10 1.6 10 15
Total: 12 16 1.6 15 25
Percentage of the requests served within a certain time (ms)
50% 15
66% 16
75% 16
80% 16
90% 16
95% 19
98% 24
99% 25
100% 25 (last request)
# more hello.c
#include <stdio.h>
main(){
printf("Content-type: text/html\n\n");
printf("Hello!");
}
# /server/apache/bin/ab -n100 -c10 'http://www.xxx.com/hello.cgi'
This is ApacheBench, Version 1.3d <$Revision: 1.58 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2001 The Apache Group, http://www.apache.org/
Benchmarking newchems.edge-china.com (be patient).....done
Server Software: Apache/1.3.22
Server Hostname: newchems.edge-china.com
Server Port: 80
Document Path: /f/hello.cgi
Document Length: 285 bytes
Concurrency Level: 10
Time taken for tests: 0.207 seconds
Complete requests: 100
Failed requests: 0
Broken pipe errors: 0
Non-2xx responses: 104
Total transferred: 48464 bytes
HTML transferred: 29640 bytes
Requests per second: 483.09 [#/sec] (mean)
Time per request: 20.70 [ms] (mean)
Time per request: 2.07 [ms] (mean, across all concurrent requests)
Transfer rate: 234.13 [Kbytes/sec] received
Connnection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 2.9 4 22
Processing: 11 14 5.5 12 38
Waiting: 6 12 5.7 10 37
Total: 11 18 5.7 16 38
Percentage of the requests served within a certain time (ms)
50% 16
66% 16
75% 20
80% 21
90% 24
95% 35
98% 38
99% 38
100% 38 (last request)