想了解一下twisted单独作为web服务器的性能。
所以用webpy写一个简单的页面,挂上twisted的wsgi跑一下。
测试代码:
以 twistd -noy test.tac的方式运行。
测试环境:
Hardware Overview:
Model Name: MacBook
Model Identifier: MacBook2,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 4 MB
Memory: 2 GB
Bus Speed: 667 MHz
测试软件 siege
1. 20并发,各10次
Transactions: 200 hits
Availability: 100.00 %
Elapsed time: 9.65 secs
Data transferred: 0.00 MB
Response time: 0.11 secs
Transaction rate: 20.73 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 2.18
Successful transactions: 200
Failed transactions: 0
Longest transaction: 0.45
Shortest transaction: 0.01
结论:
还不能下结论。
再试试twisted.web自身的。
代码:
注意,这个代码没有用twistd启动,而是直接运行了。应该区别不大。
1. 20并发,10请求
Transactions: 200 hits
Availability: 100.00 %
Elapsed time: 6.06 secs
Data transferred: 0.00 MB
Response time: 0.01 secs
Transaction rate: 33.00 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 0.18
Successful transactions: 200
Failed transactions: 0
Longest transaction: 0.02
Shortest transaction: 0.00
Transactions: 2000 hits
Availability: 100.00 %
Elapsed time: 56.31 secs
Data transferred: 0.02 MB
Response time: 0.00 secs
Transaction rate: 35.52 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 0.11
Successful transactions: 2000
Failed transactions: 0
Longest transaction: 0.03
Shortest transaction: 0.00
结论:
1.不用wsgi要快不少,尤其是在高并发的时候。
2. 不用wsgi的时候,CPU占用相当低,10%-20%之间。 用的时候,在100%以上。
仅供参考。
可能测试的不太准。原因:
1. 用了不同的运行方式。
2. 用户web,web2