Hatena::ブログ(Diary)

def __mopemope__(self, *args, **kwargs): このページをアンテナに追加 RSSフィード

 | 

2009-09-19

[]シンプルWSGIサーバ picows

WSGIサーバ勉強がてらシンプルWSGIサーバを書き始めした。

まだ全然できてませんけど。

特徴

  1. シングルスレッド
  2. 非同期
  3. WSGIのみサポート

これだけです。シンプルです。

呼び出しもシンプルでひとつのwsgi appしか載せられません。

他にもシンプルな理由は「全部Cで書いてある」って点もあるかも知れません。

ファイルもpicows.soのみです。

技術要素

  1. picoevベース
  2. ragelで吐いたrequest parser
  3. 一部のObjectはヒープに直接のっける
  4. cStringIOのAPIを直接使用

一応少しはパフォーマンスに気を使っています。

ragelベースの簡易HTTPパーサーなのでチャンクとかそういうのできません。

パフォーマンス

まだ細かい部分はできてないです、びみょーですけど。

まだロギングしてないので、同様なfapws3と単純なhello worldで比較してみます。

(それでも平等ではないですが。。。fapws3はlibevベースWSGIサーバ

picows
import picows

def simple_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type','text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']

picows.listen("0.0.0.0", 8000)
picows.run(simple_app)

picows ab

Benchmarking 0.0.0.0 (be patient)


Server Software:

Server Hostname: 0.0.0.0

Server Port: 8000

Document Path: /

Document Length: 13 bytes

Concurrency Level: 100

Time taken for tests: 2.863 seconds

Complete requests: 10000

Failed requests: 0

Write errors: 0

Total transferred: 780078 bytes

HTML transferred: 130013 bytes

Requests per second: 3492.37 [#/sec] (mean)

Time per request: 28.634 [ms] (mean)

Time per request: 0.286 [ms] (mean, across all concurrent requests)

Transfer rate: 266.05 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 4 3.5 3 33

Processing: 12 25 5.7 24 86

Waiting: 7 23 5.4 23 86

Total: 23 28 5.7 26 87

Percentage of the requests served within a certain time (ms)

50% 26

66% 28

75% 30

80% 30

90% 32

95% 34

98% 48

99% 59

100% 87 (longest request)

fapws3
import fapws._evwsgi as evwsgi
from fapws import base

    
def hello(environ, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return ["hello world!!"]

evwsgi.start("0.0.0.0", 8000)
evwsgi.set_base_module(base)

evwsgi.wsgi_cb(("/", hello))
evwsgi.run()
fapws3 ab

Benchmarking 0.0.0.0 (be patient)


Server Software: fapws3/0.3

Server Hostname: 0.0.0.0

Server Port: 8000

Document Path: /

Document Length: 13 bytes

Concurrency Level: 100

Time taken for tests: 6.899 seconds

Complete requests: 10000

Failed requests: 0

Write errors: 0

Total transferred: 1140000 bytes

HTML transferred: 130000 bytes

Requests per second: 1449.51 [#/sec] (mean)

Time per request: 68.989 [ms] (mean)

Time per request: 0.690 [ms] (mean, across all concurrent requests)

Transfer rate: 161.37 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 1 5.2 0 55

Processing: 10 67 15.4 65 128

Waiting: 4 65 15.4 63 126

Total: 27 68 13.8 65 128

Percentage of the requests served within a certain time (ms)

50% 65

66% 67

75% 69

80% 72

90% 90

95% 98

98% 108

99% 115

100% 128 (longest request)

Tornadoはロギングが入ってるので平等ではないのですが、一応のせておきます。

使用したのはdemoのhello worldです。

TornadoServer

Benchmarking 0.0.0.0 (be patient)


Server Software: TornadoServer/0.1

Server Hostname: 0.0.0.0

Server Port: 8888

Document Path: /

Document Length: 12 bytes

Concurrency Level: 100

Time taken for tests: 18.469 seconds

Complete requests: 10000

Failed requests: 0

Write errors: 0

Total transferred: 1680000 bytes

HTML transferred: 120000 bytes

Requests per second: 541.46 [#/sec] (mean)

Time per request: 184.687 [ms] (mean)

Time per request: 1.847 [ms] (mean, across all concurrent requests)

Transfer rate: 88.83 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 2 3.0 2 58

Processing: 108 181 26.5 173 374

Waiting: 107 180 26.5 172 374

Total: 116 183 27.0 175 375

Percentage of the requests served within a certain time (ms)

50% 175

66% 180

75% 187

80% 192

90% 202

95% 227

98% 265

99% 322

100% 375 (longest request)

Repository deleted — Bitbucket

 | 
Connection: close