您的位置:首页 >> Web开发 >> CGI技术 >> 正文
CGI技术 RSS
 

实战 FastCGI(转)四

http://www.rdxx.com 07年11月12日 11:04 我要投稿

关键词: FastCGI

   4. FastCGI 有多快?

看完安装 FastCGI 的阿帕契模块,以及无聊的程序设计注意事项后,我们来看看一些可以让人振奋精神的数据,效能比较 (bench mark) 总是计算机玩家的最爱 :-)

4.1 评比工具 - ApacheBench
在阿帕契服务器的套件中,有一个叫做 ab (ApacheBench) 的工具。ApacheBench 主要是用来测试阿帕契服务器执行效率用的,我们就以 ApacheBench 做为 CGI vs. FastCGI 的评比工具。

ApacheBench 可以针对某个特定的 URL 仿真出连续的联机请求,同时还可以仿真出同时间点数个相同的联机请求,因此利用 ApacheBench 可帮助我们在网站开发期间仿真实际上线可能的情况,利用仿真出来的数据做为调整服务器设定或程序的依据。 ApacheBench 的用法如下:

Usage: /usr/local/apache/bin/ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses
-p postfile File containg data to POST
-T content-type Content-type header for POSTing
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-V Print version number and exit
-k Use HTTP KeepAlive feature
-h Display usage information (this message)

假设我们要对 echo.fcg 做测试,仿真 1000 次的联机请求,而且同一时间有 20 个并行的 (concurrent) 联机请求的情况,只要在命令列模式下执行

$ ab -n 1000 -c 20 http://localhost/fcgi-bin/echo.fcg
稍等一会,ApacheBench 会把结果秀出来,

This is ApacheBench, Version 1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-1999 The Apache Group, http://www.apache.org/

Benchmarking localhost (be patient)... Server Software: Apache/1.3.6
Server Hostname: localhost
Server Port: 80
Document Path: /fcgi-bin/echo.fcg
Document Length: 995 bytes
Concurrency Level: 20
Time taken for tests: 6.859 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 1142000 bytes
HTML transferred: 995000 bytes
Requests per second: 145.79
Transfer rate: 166.50 kb/s received

Connnection Times (ms)
min avg max

Connect: 0 4 61
Processing: 62 128 771
Total: 62 132 832

以上结果指出,在同时间 20 个联机请求 (Concurrency Level) 的情况下,完成 1000 次的联机请求,共花了 6.859 秒 (Time taken for tests),因此这个程序每秒平均可以处理 (Requests per second) 145.79 个联机请求。
在接下来的评比测试中,我们就以每秒可以处理的联机请求数目来做为效能评比的依据。

4.2 CGI vs. FastCGI
前面提过利用 fcgi_stdio.h 函式库编译出来的 FastCGI 程序也兼容于 CGI 模式,因此我们只要把 fcgi-devkit-2.1 套件附的范例程序 echo.fcg 复制到 /cgi-bin 目录下,并且把文件名改成 echo.cgi,这支范例程序就可分别以 CGI 模式和 FastCGI 模式来执行,并且做比较。

首先分别对 CGI模式执行的 http://localhost/cgi-bin/echo.cgi 以及 FastCGI 模式的 http://localhost/fcgi-bin/echo.fcg 连续送出 10, 100, 1000, 10000 次的联机请求,得到的平均每秒可处理的请求 (Requests per second) 结果为:

联机数目 10 100 1000 10000
CGI 52.63 53.08 52.24 51.49
FastCGI (static mode) 204.08 224.22 146.78 207.14

接下来再分别以
9 7 3 1 2 4 8 :

 
 
标签: FastCGI 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站