CGI和FastCGI的性能区别

November 15, 2009

首先介绍一下我机器的配置:

byang@byang-desktop:~$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 2
model name      : Intel(R) Pentium(R) 4 CPU 2.60GHz
stepping        : 9
cpu MHz         : 2600.247
cache size      : 512 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up pebs bts cid xtpr
bogomips        : 5200.49
clflush size    : 64

我在机器上架设了lighttpd并且配置了CGI和FastCGI支持,然后使用apache的benchmark工具ab分别测试了静态html文件,cgi脚本和fastcgi脚本的吞吐率。测试命令:

byang@byang-desktop:~$ ab -c 50 -n 5000 http://127.0.0.1/test.cgi

Static HTML file:

Server Software:        lighttpd/1.4.19
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        3569 bytes

Concurrency Level:      50
Time taken for tests:   2.070 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      19135000 bytes
HTML transferred:       17845000 bytes
Requests per second:    2415.29 [#/sec] (mean)
Time per request:       20.701 [ms] (mean)
Time per request:       0.414 [ms] (mean, across all concurrent requests)
Transfer rate:          9026.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        8   10   1.1     10      19
Processing:     3   10   1.2     10      20
Waiting:        1    6   3.1      5      19
Total:         14   21   1.2     20      28

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

CGI:

Server Software:        lighttpd/1.4.19
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /test.cgi
Document Length:        22 bytes

Concurrency Level:      50
Time taken for tests:   9.376 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      840000 bytes
HTML transferred:       110000 bytes
Requests per second:    533.29 [#/sec] (mean)
Time per request:       93.758 [ms] (mean)
Time per request:       1.875 [ms] (mean, across all concurrent requests)
Transfer rate:          87.49 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       9
Processing:    33   94   9.1     93     137
Waiting:       31   93   9.1     93     136
Total:         40   94   9.1     93     137

Percentage of the requests served within a certain time (ms)
  50%     93
  66%     97
  75%    100
  80%    101
  90%    104
  95%    109
  98%    117
  99%    121
 100%    137 (longest request)

FastCGI:

Server Software:        lighttpd/1.4.19
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /test.fcgi
Document Length:        731 bytes

Concurrency Level:      50
Time taken for tests:   2.308 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      4385000 bytes
HTML transferred:       3655000 bytes
Requests per second:    2166.07 [#/sec] (mean)
Time per request:       23.083 [ms] (mean)
Time per request:       0.462 [ms] (mean, across all concurrent requests)
Transfer rate:          1855.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.6      0      18
Processing:     5   23   4.8     22      46
Waiting:        1   22   5.0     22      46
Total:          9   23   4.6     23      46

Percentage of the requests served within a certain time (ms)
  50%     23
  66%     25
  75%     26
  80%     27
  90%     28
  95%     30
  98%     34
  99%     40
 100%     46 (longest request)

注意看,三种文件的Requests per second的数值

Static HTML:  2415.29
CGI:             533.29
FastCGI:       2166.07

可以看到,FastCGI的性能几乎是CGI的4倍。同时,对于一台普通的PC机器,其采用Lighttpd+FastCGI的性能还是相当可观的。

  • Share/Bookmark

12 Responses to “CGI和FastCGI的性能区别”

  1. “可以看到,CGI性FastCGI的性能整整是能的4倍。”
    最后这个结论是什么意思呀?

  2. 汗啊,笔误啊,呵呵,多谢指正

  3. PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Pillspot.org. Vitamins@buy.online” rel=”nofollow”>.…

    Categories: Pain Relief.Skin Care.Antidepressants.Stomach.Mens Health.Womens Health.Stop SmokingAnti-allergic/Asthma.Weight Loss.Anxiety/Sleep Aid.Blood Pressure/Heart.Antidiabetic.Vitamins/Herbal Supplements.Eye Care.Mental HealthAntibiotics.Anti…


  4. Pillspot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Best quality drugs. Low price drugs. Buy pills online

    Buy:Zyban.Mega Hoodia.Accutane.Prevacid.Actos.Lumigan.Petcam (Metacam) Oral Suspension.Valtrex.Arimidex.Retin-A.Prednisolone.Nexium.Synthroid.Human Growth Hormone.100% Pure Okinawan Coral Calcium.Zovirax….

  5. r\x3dh http://ACEHARDWAREE.INFO/tag/r\x3dh : au KitchenAid review/…

    r\x3dh…

  6. au digital camera/ http://ACEHARDWAREE.INFO/tag/r\x3dh : au digital camera/…

    r\x3dh…

  7. child safe/ http://BESTPARTSPLUS.INFO/tag/download : child safe/…

    child safe/…

  8. Pinatas http://aelectricmol.BABYCLOTHESNUT.INFO/tag/Pinatas+party+Cone/ : Pinatas…

    party…

  9. suunto http://fsuuntojxff.AWESOMEBABYCLOTHES.INFO/tag/T4+canada+suunto/ : suunto…

    T4…

  10. Dorm http://wfloatinguattm.BABYCLOTHESNUT.INFO/tag/Preparing+for+Life+Dorm/ : for…

    Life…

  11. Power http://ustrawberryawgw6lu.04FORDPARTS.US/tag/tactical+Power+power/ : power…

    Power…

  12. toy http://ncherryg2qckkv.copious-systems.com/tag/doms+car+and+toy/ : toy…

    car…

Leave a Reply