django自带wsgi server vs 部署uwsgi+nginx后的性能对比

时间:2021-09-01 21:05:21

一.下面先交代一下测试云主机

cpu:

root@alexknight:/tmp/webbench-1.5# cat /proc/cpuinfo |grep model
model        : 69
model name    : Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz
root@alexknight:/tmp/webbench-1.5#

mem:

root@alexknight:/tmp/webbench-1.5# free -m
             total       used       free     shared    buffers     cached
Mem:           490        364        125          3         41        103
-/+ buffers/cache:        219        270
Swap:          509        208        301

二.测试对比

测试工具为webbench.

  • 下面是django自带wsgi webserver的性能
root@alexknight:/tmp/webbench-1.5# webbench -c 20 -t 30 http://115.28.21.25:8008/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://115.28.21.25:8008/
20 clients, running 30 sec.

Speed=554 pages/min, 129959 bytes/sec.
Requests: 277 susceed, 0 failed.

大概能承受20路并发,当上升到25路时,会开始出现失败请求。

  • 下面用uwsgi+nginx取代自带的wsgi server
root@alexknight:/tmp/webbench-1.5# webbench -c 170 -t 30 http://115.28.21.25:8000/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://115.28.21.25:8000/
170 clients, running 30 sec.

Speed=640 pages/min, 126746 bytes/sec.
Requests: 320 susceed, 0 failed.

大概能承受170路并发,效果还算明显的,当请求继续上升时,就会开始出现失败请求。