Fork me on GitHub

2010/04/01


このエントリーをはてなブックマークに追加
rubyのmongrelやthinなんかに変わるhttpdでUnicornとやらがあるのを知った。
ひとまずベンチ取ってみた。rubyでやる専用なのでなにかアプリを書かないと動かないのかな?とりあえずsinatraアプリ書いた。

unicorn-test.rb
require 'rubygems'
require 'sinatra'
set :public, File.dirname(__FILE__)
config.ru
require 'unicorn-test'
run Sinatra::Application
で、unicorn実行。ベンチは
# ab -n 1000 -c 10 -k http://localhost:8080/helloworld.html 2>&1 | tee unicorn.log
で確認した。

unicornの結果

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /helloworld.html
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   5.385 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      193386 bytes
HTML transferred:       11022 bytes
Requests per second:    185.69 [#/sec] (mean)
Time per request:       53.855 [ms] (mean)
Time per request:       5.385 [ms] (mean, across all concurrent requests)
Transfer rate:          35.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:    12   53  43.2     33     260
Waiting:       11   53  43.1     32     260
Total:         12   54  43.1     33     260

Percentage of the requests served within a certain time (ms)
  50%     33
  66%     42
  75%     56
  80%    106
  90%    119
  95%    140
  98%    176
  99%    212
 100%    260 (longest request)
一応、prefork付きのapache2でも...
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


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

Document Path:          /helloworld.html
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   0.341 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    996
Total transferred:      322825 bytes
HTML transferred:       11000 bytes
Requests per second:    2931.25 [#/sec] (mean)
Time per request:       3.412 [ms] (mean)
Time per request:       0.341 [ms] (mean, across all concurrent requests)
Transfer rate:          924.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    3   7.8      0      40
Waiting:        0    3   7.8      0      40
Total:          0    3   7.8      0      40

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%     18
  95%     21
  98%     32
  99%     35
 100%     40 (longest request)
いちおうのいちおうでtthttpd(tinytinyhttpd)でも
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8081

Document Path:          /helloworld.html
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   0.431 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1000
Total transferred:      183000 bytes
HTML transferred:       11000 bytes
Requests per second:    2321.65 [#/sec] (mean)
Time per request:       4.307 [ms] (mean)
Time per request:       0.431 [ms] (mean, across all concurrent requests)
Transfer rate:          414.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    4  15.1      0     241
Waiting:        0    4  15.0      0     241
Total:          0    4  15.1      0     241

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

結論: preforkつえー。


えっ?そういう調査でしたっけ...
Posted at 01:09 in ソフトウェア::httpd
Tagged as: apache2, tinytinyhttpd, tthttpd, unicorn
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2009/10/02


このエントリーをはてなブックマークに追加
tthttpd(tinytinyhttpd)にiratqqさんがIPv6対応をコードを入れてくれました。通常起動でIPv4、IPv6どちらも扱える様になっていて、引数で
# tthttpd -4
とすればIPv4だけで
# tthttpd -6
とすればIPv6だけで起動する様になります。iratqq++
また、静的なファイルをサーブする場合にはこれまでreadしながらsendしていたのですが、sendfile(2)を使う様にしました。Windowsの場合は昨日Plackの高速化対応した時の様にTransmitFileを使うようにしました。
小さいサイズのファイルだと差は出ませんが、数メガくらいのファイルから格段に差が出て速くなりました。
mattn's tinytinyhttpd at master - GitHub

tiny tiny httpd

http://github.com/mattn/tinytinyhttpd

LinuxサーバHacks―プロが使うテクニック&ツール100選 LinuxサーバHacks―プロが使うテクニック&ツール100選
ロブ フリッケンガー
オライリージャパン / ¥ 2,310 (2003-11)
 
発送可能時間:在庫あり。

Posted at 23:11 in ソフトウェア::lang::c
Tagged as: c, c++, ipv6, tinytinyhttpd, tthttpd
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2009/09/29


このエントリーをはてなブックマークに追加
久々tthttpd(tinytinyhttpd)を触っていて、動いてるだろうと思ってたkeep-aliveのコードが動いていなかった事に愕然としながら修正してたら、以前smegheadさんが報告してくれていたmingw32で落ちる問題の原因を発見。
記憶の底で、_beginthread()したらCloseHandle()しなきゃいねないと思い込んでいたんですが、どうやら_beginthread()じゃなくて_beginthreadex()の場合だけだった(参照)。_beginthread()の場合はスレッド終了時にリソース回収されるらしい。
他いろいろと修正してkeep-aliveが動くようになり、ベンチマーク取ってみた。
テストは「helloworld」と書かれたhello.txtをabでGETする物。

まずはconnection closeの場合
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /hello.txt
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   0.993 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      160000 bytes
HTML transferred:       11000 bytes
Requests per second:    1006.77 [#/sec] (mean)
Time per request:       9.933 [ms] (mean)
Time per request:       0.993 [ms] (mean, across all concurrent requests)
Transfer rate:          157.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     1   10  13.0      6     128
Waiting:        0   10  12.9      6     128
Total:          2   10  13.0      6     129

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      7
  75%      7
  80%      7
  90%     15
  95%     31
  98%     59
  99%     86
 100%    129 (longest request)
そしてconnection keep-aliveの場合
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /hello.txt
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   0.559 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1000
Total transferred:      185472 bytes
HTML transferred:       11088 bytes
Requests per second:    1789.60 [#/sec] (mean)
Time per request:       5.588 [ms] (mean)
Time per request:       0.559 [ms] (mean, across all concurrent requests)
Transfer rate:          324.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    6  19.7      1     263
Waiting:        0    5  19.0      0     262
Total:          0    6  19.8      1     263

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      4
  75%      4
  80%      4
  90%     11
  95%     22
  98%     46
  99%     80
 100%    263 (longest request)
ちなみに同じマシン(Ubuntu9.10 on CeleronM 1.5GHz 500M)で取ったapache2のベンチ。
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 1000 requests
Finished 1000 requests


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

Document Path:          /~mattn/hello.txt
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   0.771 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1000
Total transferred:      464920 bytes
HTML transferred:       11000 bytes
Requests per second:    1297.49 [#/sec] (mean)
Time per request:       7.707 [ms] (mean)
Time per request:       0.771 [ms] (mean, across all concurrent requests)
Transfer rate:          589.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.5      0       7
Processing:     6    8   3.3      7      28
Waiting:        6    7   3.1      6      27
Total:          6    8   3.3      7      28

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      7
  75%      7
  80%      7
  90%     12
  95%     16
  98%     18
  99%     27
 100%     28 (longest request)
あまりパフォーマンスは意識してなかった割には、まぁまぁな速度(Request per secondでapache2の1.5倍速くらい?)が出たんじゃないかと思います。ただ機能も小さいですしapacheにも幾らかモジュールが入っちゃってますから参考値にしかすぎませんが...
とりあえずmingw32で不意に落ちる問題が解決したのでこれからパフォーマンスも気にしながらやって行こうかなーと思います。


Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES) Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES)
スコット・メイヤーズ
ピアソン・エデュケーション / ¥ 3,990 (2006-04-29)
 
発送可能時間:在庫あり。


Effective STL―STLを効果的に使いこなす50の鉄則 Effective STL―STLを効果的に使いこなす50の鉄則
スコット メイヤーズ
ピアソンエデュケーション / ¥ 3,360 (2002-01)
 
発送可能時間:在庫あり。

Posted at 22:57 in ソフトウェア::lang::c
Tagged as: c, tinytinyhttpd, tthttpd
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2009/08/18


このエントリーをはてなブックマークに追加
色々と修正を施して、sinatraのdispatch.cgiも動くようになっています。またBASIC認証をサポートしましたので、tDiaryのupdate.rbだけに認証をかけられる様になっています。実際には、ターゲットURL、メソッド(GET/POSTなど)、ユーザ・パスワード一覧という設定が可能になったので、複数ユーザを扱う事も出来ます。
ただ現状、プレインテキストのみ対応ですので、これについては今後なんとかして行きたいと思っています。

本当ならば.htaccessを読み込ませたいのですが、.htaccessはcrypt/md5を使って暗号化されており、libcryptを使うとなれば依存が増えると同時に、ライセンス的にもグレーになってきますので、少し悩んでいます。どこかにPublic Domainで書かれたlibcrypt知りませんか?
Posted at 00:10 in ソフトウェア::lang::c
Tagged as: tinytinyhttpd, tthttpd
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip