django的几种运行方法性能对比
所有的测试均为我的笔记本,这里测试的环境都一样。?
OS:OS X 10.4.10?
CPU:2.16GHz Intel Core Duo?
RAM:2G 667MHz SDRAM?
lighttpd:lighttpd @1.4.18_0+darwin_8?
python:python25 @2.5.1_1+darwin_8?
django:0.97-pre-SVN-unknown
测试工具:apache ab?
测试压力:50个并发、连续5000次访问
测试服务器内容:就是一个url请求,echo出Hello World。
使用django的自带server:?
Concurrency Level: 50?
Time taken for tests: 8.511 seconds?
Complete requests: 5000?
Failed requests: 122?
(Connect: 70, Length: 52, Exceptions: 0)?
Broken pipe errors: 0?
Total transferred: 759220 bytes?
HTML transferred: 103530 bytes?
Requests per second: 587.48 [#/sec] (mean)?
Time per request: 85.11 [ms] (mean)?
Time per request: 1.70 [ms] (mean, across all concurrent requests)?
Transfer rate: 89.20 [Kbytes/sec] received
它在连接访问的末期在控制台上报出了许多exception。每秒587次的处理能力还是相当不错的,不过稳定性不好还是需要大家仔细考虑的。
再来看看lighttpd+fastcgi+threaded的结果:?
Concurrency Level: 50?
Time taken for tests: 8.447 seconds?
Complete requests: 5000?
Failed requests: 1?
(Connect: 0, Length: 1, Exceptions: 0)?
Broken pipe errors: 0?
Total transferred: 862279 bytes?
HTML transferred: 104979 bytes?
Requests per second: 591.93 [#/sec] (mean)?
Time per request: 84.47 [ms] (mean)?
Time per request: 1.69 [ms] (mean, across all concurrent requests)?
Transfer rate: 102.08 [Kbytes/sec] received?
哈哈,处理能力明显比django自己的server要好。不过在最后一次也出现了问题,更讨厌的是它在出现问题后就死悄悄了,必需重启lighttpd和django才能缓过来。稳定第一,这样的稳定问题还是不能让我容忍的!
是不是lighttpd+fastcgi+prefork方式会稳定的多呢?来看看:?
Concurrency Level: 50?
Time taken for tests: 57.002 seconds?
Complete requests: 5000?
Failed requests: 5000?
(Connect: 5000, Length: 0, Exceptions: 0)?
Broken pipe errors: 0?
Total transferred: 0 bytes?
HTML transferred: 0 bytes?
Requests per second: 87.72 [#/sec] (mean)?
Time per request: 570.02 [ms] (mean)?
Time per request: 11.40 [ms] (mean, across all concurrent requests)?
Transfer rate: 0.00 [Kbytes/sec] received?
真的没有错误了。不过让人无法忍受!感觉就一个字:“慢!”每秒87次的处理能力能让人杀了我!虽然稳定。。。但是看着大片大片的cpu空着,感觉对不起我这PP的BB哟。
大将出场!牛B的scgi来了,lighttpd+scgi+threaded强强联合:?
Concurrency Level: 50?
Time taken for tests: 6.202 seconds?
Complete requests: 5000?
Failed requests: 0?
Broken pipe errors: 0?
Total transferred: 934460 bytes?
HTML transferred: 105000 bytes?
Requests per second: 806.19 [#/sec] (mean)?
Time per request: 62.02 [ms] (mean)?
Time per request: 1.24 [ms] (mean, across all concurrent requests)?
Transfer rate: 150.67 [Kbytes/sec] received?
这才是真正牛B的每秒806次处理,而且没有问题,而且cpu很稳当。爽就一个字!
是不是scgi在prefork方式下也很强呢?来看看lighttpd+scgi+prefork的成绩:?
Concurrency Level: 50?
Time taken for tests: 56.730 seconds?
Complete requests: 5000?
Failed requests: 5000?
(Connect: 5000, Length: 0, Exceptions: 0)?
Broken pipe errors: 0?
Total transferred: 0 bytes?
HTML transferred: 0 bytes?
Requests per second: 88.14 [#/sec] (mean)?
Time per request: 567.30 [ms] (mean)?
Time per request: 11.35 [ms] (mean, across all concurrent requests)?
Transfer rate: 0.00 [Kbytes/sec] received?
山口再次吹来了凉风,只能用“凄惨”来形容。又是一个稳定而无任何性能而言的成绩。
看了这些数字,总结一下:?
1.django服务器的prefork是稳定第一,但是显然不如thread状态下的速度快?
2.thread处理速度是快,但是到一个临界状态后出错哪可是一踏里糊涂呀?
3.scgi比fcgi的简洁不是盖的,对于cpu的消耗就是小,而且实现比较稳定
后话:?
除了django自己的server外,其它的模式如果你改了程序,就需要kill -HUP django启动的cgi服务。在开发时还是使用django自己的server罢。但是在生产环境中重启server还是有点不爽。 :)