lighttpdよりも人気(?)のWebサーバ:nginx

|
さて。もう一つ別のWebサーバでのFastCGI設定を晒しておきましょう。nginxというWebサーバです。かなりマイナーですが,以下のような特長があります。
  • 高速:条件にもよるがlighttpdよりも速い
  • FastCGI対応:ただし,FastCGIプロセス管理をきっぱり切り捨て,external-server専用と割り切っています
  • FastCGIに渡すパラメータを自分で設定:分かりやすいですし,変なこともできそうです
  • なんか最近開発が盛んっぽい:2月だけで10回バージョンアップしてます
  • 日本ではほとんど知られていない:Gentooのportageにあったから知りました
  • そもそも英語の情報すらもない:オフィシャルはロシア語。露英翻訳をかければ何となく分かります
  • 実はlighttpdよりメジャー?:Netcraft Web Server Surveyではlighttpdよりも上にいる!(.comでの比較だと逆転するあたり,「国産だから」とロシア人が使っているのでしょうか。
全体の設定はこんな感じです。(Gentooのデフォルト) # /etc/nginx/nginx.conf user  apache apache; worker_processes  1; error_log /var/log/nginx/error_log info; events {         worker_connections  8192;         use epoll; } http {         include         /etc/nginx/mime.types;         default_type    application/octet-stream;         log_format main                 '$remote_addr - $remote_user [$time_local] '                 '"$request" $status $bytes_sent '                 '"$http_referer" "$http_user_agent" '                 '"$gzip_ratio"';         client_header_timeout   10m;         client_body_timeout     10m;         send_timeout            10m;         connection_pool_size            256;         client_header_buffer_size       1k;         large_client_header_buffers     4 2k;         request_pool_size               4k;         gzip on;         gzip_min_length 1100;         gzip_buffers    4 8k;         gzip_types      text/plain;         output_buffers  1 32k;         postpone_output 1460;         sendfile        on;         tcp_nopush      on;         tcp_nodelay     on;         keepalive_timeout       75 20;         ignore_invalid_headers  on;         server {                 listen          :10080;                 server_name     localhost;                 access_log      /var/log/nginx/access_log combined;                 root /var/www/localhost/htdocs;                 include /etc/nginx/catalyst-multi.conf;         } }   includeしているcatalyst-multi.confでCatalyst FastCGIアプリの設定をしています。lighttpdよりもシンプルに書けているような。 # /etc/nginx/catalyst-multi.conf rewrite ^/app1(\?.*)?$ /app1/$1 redirect; location /app1/static/ {     alias /path/to/App1/root/static/; } location /app1/ {     if ( $request_uri ~ ^/app1(/[^\?]*)(\?.*)?$ ) {         set $script_name /app1;         set $path_info $1;     }     fastcgi_pass 127.0.0.1:10021;     include /etc/nginx/catalyst-params; } rewrite ^/app2(\?.*)?$ /app2/$1 redirect; location /app2/static/ {     alias /path/to/App2/root/static/; } location /app2 {     if ( $request_uri ~ ^/app(/[^\?]*)(\?.*)?$ ) {         set $script_name /app2;         set $path_info $1;     }     fastcgi_pass 127.0.0.1:10022;     include /etc/nginx/catalyst-params; }   FastCGIプロセスに渡すパラメータは自分で全部書きます。lighttpdのextensionの値による変化とかが無いのですっきりです。 fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param REQUEST_URI $request_uri; fastcgi_param QUERY_STRING $query_string; # SCRIPT_NAME, PATH_INFO: MUST be set by each apps. fastcgi_param SCRIPT_NAME $script_name; fastcgi_param PATH_INFO $path_info; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SERVER_SOFTWARE nginx/0.3.30; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param REDIRECT_STATUS 200;   lighttpdのベンチ。 $ /usr/sbin/ab2 -k -c 10 -n 1000 http://localhost:8081/index.html.en 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) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests Server Software:        lighttpd/1.4.10 Server Hostname:        localhost Server Port:            8081 Document Path:          /index.html.en Document Length:        1456 bytes Concurrency Level:      10 Time taken for tests:   0.94677 seconds Complete requests:      1000 Failed requests:        0 Write errors:           0 Keep-Alive requests:    1000 Total transferred:      1711000 bytes HTML transferred:       1456000 bytes Requests per second:    10562.23 [#/sec] (mean) Time per request:       0.947 [ms] (mean) Time per request:       0.095 [ms] (mean, across all concurrent requests) Transfer rate:          17638.92 [Kbytes/sec] received Connection Times (ms)               min  mean[+/-sd] median   max Connect:        0    0   0.1      0       1 Processing:     0    0   0.2      0       2 Waiting:        0    0   0.0      0       0 Total:          0    0   0.3      0       2 Percentage of the requests served within a certain time (ms)   50%      0   66%      0   75%      0   80%      0   90%      0   95%      1   98%      1   99%      1  100%      2 (longest request)   nginxのベンチ。 $ /usr/sbin/ab2 -k -c 10 -n 1000 http://localhost:10080/index.html.en 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) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests Server Software:        nginx/0.3.30 Server Hostname:        localhost Server Port:            10080 Document Path:          /index.html.en Document Length:        1456 bytes Concurrency Level:      10 Time taken for tests:   0.74691 seconds Complete requests:      1000 Failed requests:        0 Write errors:           0 Keep-Alive requests:    1000 Total transferred:      1712000 bytes HTML transferred:       1456000 bytes Requests per second:    13388.49 [#/sec] (mean) Time per request:       0.747 [ms] (mean) Time per request:       0.075 [ms] (mean, across all concurrent requests) Transfer rate:          22372.17 [Kbytes/sec] received Connection Times (ms)               min  mean[+/-sd] median   max Connect:        0    0   0.0      0       0 Processing:     0    0   0.1      0       1 Waiting:        0    0   0.0      0       0 Total:          0    0   0.1      0       1 Percentage of the requests served within a certain time (ms)   50%      0   66%      0   75%      0   80%      0   90%      0   95%      0   98%      0   99%      1  100%      1 (longest request)   2割ばかし速いですね。configureとか見ると,CPUの名前を入れさせてキャッシュラインのサイズに合わせて内部のデータ構造を調整しているっぽいです。で,適当に入れたんですけどそれがあたっていたようで。 # cat /proc/cpuinfo processor       : 0 vendor_id       : GenuineIntel cpu family      : 6 model           : 13 model name      : Intel(R) Celeron(R) M processor         1.30GHz stepping        : 6 cpu MHz         : 1300.221 cache size      : 1024 KB 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 mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss tm pbe bogomips        : 2603.37   上のベンチはこんな環境でやってましたが,別のEM64Tな環境でテストするとlighttpdとあまり差が出ませんでした(どちらも7000req/sくらい)。自前で調整すれば速くなるのかもしれませんが,Celeron Dはキャッシュが小さくってダメそうですね。あれ? ってことは,キャッシュの恩恵が大きすぎてベンチの意味がない? うーん。ま,いっか。本気で使おうってつもりじゃないので。

Trackback URL for this post:

http://old.typemiss.net/trackback/75