星期五, 十月 06, 2006

几种Apache CGI模块性能简单分析比较

最近对  mod_python, mod_php, mod_ruby, mod_lua做一个简单的性能比较,目的是想知道mod_lua在性能方面该如何改进!

工作在Windows 2003, VS 2005下完成,全部采用动态编译
-
mod_python已被捐赈给apache由apache关方维护,轻松搞定(支持python 2.4,不支持python2.5)
mod_php 一直被作为CGI开发的热点,也非常容易搞定
mod_lua 是本人的开源项目,自然不用碰到问题(支持最新lua 5.1.1)
mod_ruby 这个小日本的东西,在他上面花的时间最多, 首先与yarv(ruby 2.0)还不兼容,另外在ruby 1.8.5的编译时候需要在程序内部切换一个宏,另外还有个内存问题! 文档资料也很少.(mod_lua根本还没有文档,我以后会陆续给出)!需要一定的经验,不能自动完成.

( 就我对apache与ruby的了解程度自信可以搞定, 对于小日本开源软件的态度还真不敢恭维,ROR不知是被那位炒起来的, 反正mod_ruby的性能不敢恭维.)

---PHP的测试
页面
echo "Hello World!";
命令行
ab -n 100 http://localhost/tmp/hello.php

输出结果
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.0.59
Server Hostname: localhost
Server Port: ; &nbsp; 80

Document Path: &nbsp; ; /tmp/hello.php
Document Length: 12 bytes

Concurrency Level: &nbsp; &nbsp; 1

Time taken for tests: 0.609375 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 28700 bytes
HTML transferred: 1200 bytes
Requests per second: 164.10 [#/sec] (mean)
Time per request: 6.094 [ms] (mean)
Time per request: 6.094 [ms] (mean, across all concurrent requests)
Transfer rate: 45.95 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.1 0 15
Processing: 0 4 7.2 0 15
Waiting: 0 4 7.1 0 15
Total: 0 5 7.2 0 15

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

------mod_pythonde的测试
页面
from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK
命令行
ab -n 100 http://localhost/tmp/hello.py
输出结果
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.nutstech.com (be patient).....done


Server Software: Apache/2.0.59
Server Hostname: www.nutstech.com
Server Port: 80

Document Path: /tmp/hello.py
Document Length: 12 bytes

Concurrency Level: 1
Time taken for tests: 0.359375 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 20500 bytes
HTML transferred: 1200 bytes
Requests per second: 278.26 [#/sec] (mean)
Time per request: 3.594 [ms] (mean)
Time per request: 3.594 [ms] (mean, across all concurrent requests)
Transfer rate: 55.65 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.6 0 15
Processing: 0 2 5.7 0 15
Waiting: 0 2 5.2 0 15
Total: 0 3 6.0 0 15

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

-----mod_lua的测试
页面程序
http.print("Hello World!")
命令行
ab -n 100 http://localhost/tmp/hello.lua
测试结果
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.0.59
Server Hostname: localhost
Server Port: 80

Document Path: /tmp/hello.lua
Document Length: 12 bytes

Concurrency Level: 1
Time taken for tests: 0.468750 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 24200 bytes
HTML transferred: 1200 bytes
Requests per second: 213.33 [#/sec] (mean)
Time per request: 4.688 [ms] (mean)
Time per request: 4.688 [ms] (mean, across all concurrent requests)
Transfer rate: 49.07 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.6 0 15
Processing: 0 3 6.6 0 31
Waiting: 0 2 6.0 0 15
Total: 0 3 6.9 0 31

Percentage of the requests served within a certain time (ms)
50% 0
66% 0
75% 0
80% 15
90% 15
95% 15
98% 15
99% 31
100% 31 (longest request)

----mod_ruby的测试
页面
#!/usr/bin/ruby

require "cgi"

cgi = CGI.new
print cgi.header("type"=>"text/plain")
print "Hello World!"


命令
ab -n 100 http://localhost/tmp/hello.rbx
测试结果
 This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.0.59
Server Hostname: localhost
Server Port: 80

Document Path: /tmp/hello.rbx
Document Length: 12 bytes

Concurrency Level: 1
Time taken for tests: 1.187500 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 24300 bytes
HTML transferred: 1200 bytes
Requests per second: 84.21 [#/sec] (mean)
Time per request: 11.875 [ms] (mean)
Time per request: 11.875 [ms] (mean, across all concurrent requests)
Transfer rate: 19.37 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.1 0 15
Processing: 0 10 9.1 15 46
Waiting: 0 9 9.1 15 46
Total: 0 10 9.1 15 46

Percentage of the requests served within a certain time (ms)
50% 15
66% 15
75% 15
80% 15
90% 15
95% 31
98% 31
99% 46
100% 46 (longest request)

This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.0.59
Server Hostname: localhost
Server Port: 80

Document Path: /tmp/hello.rbx
Document Length: 12 bytes

Concurrency Level: 1
Time taken for tests: 1.187500 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 24300 bytes
HTML transferred: 1200 bytes
Requests per second: 84.21 [#/sec] (mean)
Time per request: 11.875 [ms] (mean)
Time per request: 11.875 [ms] (mean, across all concurrent requests)
Transfer rate: 19.37 [Kbytes/sec] received


Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.1 0 15
Processing: 0 10 9.1 15 46
Waiting: 0 9 9.1 15 46
Total: 0 10 9.1 15 46

Percentage of the requests served within a certain time (ms)
50% 15
66% 15
75% 15
80% 15
90% 15
95% 31
98% 31
99% 46
100% 46 (longest request)



结果比较:


  • 模块名称 结果(次/秒)
  • mod_python 278.26
  • mod_lua 213.33
  • mod_php 164.10
  • mod_ruby 84.21
mod_python的处理速度果然快, 难怪google实用了很多的python, 不要犹豫, 用python吧!
当然php在WEB开发中的地位已经巩固, 但我相信很快就会被python赶上并超越
我开发的mod_lua,是为嵌入式应用准备的,在执行速度与模块大小方面都不错!且可直接用共享内存来通信 具体大家可以到 http://sf.net/projects/modlua 去了解!
mod_ruby是在是不敢恭维,如果采用eruby估计会更慢,将用ruby开发web的人,需要仔细考虑了


没有评论: