Wheatserver是通用的C实现的通用服务器以及框架,更多的请参考Wheatserver
WSGI应用服务器众多,较为出色的有uWSGI,Gunicorn,gevent和Apache mod_wsgi。性能评测参考http://nichol.as/benchmark-of-python-web-servers
为了比较Wheatserver的性能并且为了省事,我选取了在该评测中性能最为出色的gevent实现的WSGI应用服务器,主要考查了内存消耗,简单App下相应速度,带数据库连接的相应速度和带搜索的服务访问能力。Http测试客户端使用Apache ab。
由于Wheatserver是多工作进程模式,而gevent是单进程单线程模式,所以为了避免Wheatserver多进程的干扰,我们同样只使用一个进程的Wheatserver。
同样是Hello world应用
#!/usr/bin/python
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ["<b>hello world</b>"]
Server Software: gevent Server Hostname: 127.0.0.1 Server Port: 8088 Document Path: / Document Length: 18 bytes Concurrency Level: 50 Time taken for tests: 0.056 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 13800 bytes HTML transferred: 1800 bytes Requests per second: 1773.33 [#/sec] (mean) Time per request: 28.196 [ms] (mean) Time per request: 0.564 [ms] (mean, across all concurrent requests) Transfer rate: 238.98 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 1.2 1 7 Processing: 2 21 10.3 21 50 Waiting: 2 21 10.5 21 50 Total: 3 23 10.7 23 50 Percentage of the requests served within a certain time (ms) 50% 23 66% 30 75% 31 80% 32 90% 35 95% 39 98% 49 99% 50 100% 50 (longest request)
Server Software: wheatserver
Server Hostname: 127.0.0.1
Server Port: 10828
Document Path: /
Document Length: 13 bytes
Concurrency Level: 50
Time taken for tests: 0.021 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 15500 bytes
HTML transferred: 1300 bytes
Requests per second: 4704.55 [#/sec] (mean)
Time per request: 10.628 [ms] (mean)
Time per request: 0.213 [ms] (mean, across all concurrent requests)
Transfer rate: 712.12 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.7 1 2
Processing: 1 7 2.4 8 10
Waiting: 1 7 2.4 8 10
Total: 2 8 1.9 8 11
Percentage of the requests served within a certain time (ms)
50% 8
66% 9
75% 9
80% 9
90% 9
95% 10
98% 10
99% 11
100% 11 (longest request)
简单App下,平均相应时间是gevent的二分之一,主要是没有IO操作,C实现的Wheatserver自然更快。
Server Software: wheatserver
Server Hostname: 127.0.0.1
Server Port: 10828
Document Path: /
Document Length: 11995 bytes
Concurrency Level: 5
Time taken for tests: 0.709 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1226700 bytes
HTML transferred: 1199500 bytes
Requests per second: 141.08 [#/sec] (mean)
Time per request: 35.441 [ms] (mean)
Time per request: 7.088 [ms] (mean, across all concurrent requests)
Transfer rate: 1690.05 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 9 35 3.8 35 42
Waiting: 9 34 3.8 35 42
Total: 10 35 3.7 35 42
Percentage of the requests served within a certain time (ms)
50% 35
66% 36
75% 36
80% 37
90% 38
95% 39
98% 41
99% 42
100% 42 (longest request)
Server Software: gevent
Server Hostname: 127.0.0.1
Server Port: 8088
Document Path: /
Document Length: 11995 bytes
Concurrency Level: 5
Time taken for tests: 0.779 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1224600 bytes
HTML transferred: 1199500 bytes
Requests per second: 128.39 [#/sec] (mean)
Time per request: 38.944 [ms] (mean)
Time per request: 7.789 [ms] (mean, across all concurrent requests)
Transfer rate: 1535.43 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 8 38 5.3 38 51
Waiting: 8 38 5.3 38 51
Total: 9 38 5.3 38 51
Percentage of the requests served within a certain time (ms)
50% 38
66% 39
75% 39
80% 40
90% 42
95% 48
98% 51
99% 51
100% 51 (longest request)
在带有数据库连接的访问中,我们可以发现两者相差不多,响应时间主要以IO为主,Wheatserver略微占优。
Server Software: wheatserver
Server Hostname: 127.0.0.1
Server Port: 10828
Document Path: /result/love/
Document Length: 15461 bytes
Concurrency Level: 5
Time taken for tests: 2.556 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1573300 bytes
HTML transferred: 1546100 bytes
Requests per second: 39.12 [#/sec] (mean)
Time per request: 127.814 [ms] (mean)
Time per request: 25.563 [ms] (mean, across all concurrent requests)
Transfer rate: 601.04 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 24 125 16.2 124 158
Waiting: 24 125 16.2 124 158
Total: 25 125 16.2 124 158
Percentage of the requests served within a certain time (ms)
50% 124
66% 125
75% 131
80% 135
90% 141
95% 150
98% 157
99% 158
100% 158 (longest request)
Server Software: gevent
Server Hostname: 127.0.0.1
Server Port: 8088
Document Path: /result/love/
Document Length: 15461 bytes
Concurrency Level: 5
Time taken for tests: 2.556 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1571200 bytes
HTML transferred: 1546100 bytes
Requests per second: 39.12 [#/sec] (mean)
Time per request: 127.806 [ms] (mean)
Time per request: 25.561 [ms] (mean, across all concurrent requests)
Transfer rate: 600.28 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 25 125 15.8 125 157
Waiting: 25 125 15.7 125 157
Total: 26 125 15.8 125 157
Percentage of the requests served within a certain time (ms)
50% 125
66% 126
75% 128
80% 129
90% 143
95% 146
98% 155
99% 157
100% 157 (longest request)
在带搜索服务的对比上,可以发现两者更为一致,基本不分伯仲。
最后看一下两者在内存上对比,gevent在同样App下保持37MB的内存,而Wheatserver同样以35MB差不多。值得注意的是Wheatserver的内存消耗量多是因为Python应用的运行和预分配内存机制的存在,在实际运行中,Wheatserver的内存量会比gevent略低。考虑到gevent依赖libevent,greenlet等库,内存量应该稍多于Wheatserver。但gevent以Python实现的服务器能达到如此低的内存也令人惊讶。
Wheatserver在作为Http服务器方面由于IO比重大,主要CPU时间在应用上,因此优势比之Gevent不大。在静态文件发送上,Wheatserver可以做到与Nginx媲美的响应速度和能力,并且是在Wheatserver并没有使用缓存的基础上。
转载请注明:爱开源 » Wheatserver与Gevent作为WSGI服务器的性能评测