用C写的CGI程序和在mod_perl环境下运行的Perl程序,真的有这么大的差距吗?

lewistie 2002-01-05 11:45:09
这是我写的两个测试程序,运行在同一个目录下,这个目录配置了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)
...全文
133 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
peifang 2002-01-11
  • 打赏
  • 举报
回复
关于PHP的稳定性我倒是没有测试过,因为不大了解PHP。

Mod_perl的并发访问能力我倒是简略地测试过,有优点也有缺点,优点是看起来稳定性还过得去,缺点是内存占用率吓人。

不过内存占用率的问题倒不一定是mod_perl的责任,可能因为perl的内存管理和GC机制的原因。
peifang 2002-01-07
  • 打赏
  • 举报
回复
其实做php和mod_perl比较到还是有趣的。结果是php的加载速度要比mod_perl快不少,但是不能确信php的脚本解释速度就比perl快。
peifang 2002-01-07
  • 打赏
  • 举报
回复
呵呵呵,其实做C和perl的比较本来就不公平,两者没有可比性啊。
你的同事好像很多啊,花无缺也是你的同事?
wac2000 2002-01-07
  • 打赏
  • 举报
回复
peifang:lewistie是我同事,他的意思就是说c快,其实这种c和mod_perl的比较本来就是不公平的,一个是CGI方式,一个是mod_perl,如果真正要比较的话,可以采用FastCGI(C来实现)和mod_perl(Perl实现),这样相对公平一些。
peifang 2002-01-05
  • 打赏
  • 举报
回复
给lewistie:
我说的意思是你这个测试太不具有代表性了。
仅仅一行printf("hello");这种语句对任何语言都几乎是相同快的。结果你的比较成了哪个文件加载快了,而不是哪种方式更快。所以说你不能依据此而得出结论。

给wac2000
呵呵呵,我当然明白mod_perl的工作方式了。
wac2000 2002-01-05
  • 打赏
  • 举报
回复
peifang,你明白mod_perl和C的工作方式吗?什么叫做结论是错的?why?
lewistie 2002-01-05
  • 打赏
  • 举报
回复
请说详细些。
peifang 2002-01-05
  • 打赏
  • 举报
回复
结果是对的,但是结论是错的。呵呵呵。

2,203

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧