伺服器环境:阿里云最低配置,1核CPU,512M内存,1M带宽。

测试页面:纯动态列表页架构:Django + uwsgi + PostgreSQL + memcache + Nginx

用webbench测试了一下,在10并发的时候,用户可以勉强访问网站,监视的时候发现CPU彪的最高的是uwsgi进程,我开了64个子进程

请问还有优化空间吗,有没有代替uwsgi更好的方案来提高并发数?正常访问的时候,动态页面响应时间在100ms左右


workers, processes

Argument: number

Spawn the specified number of workers/processes.

This option may be set with -p from the command line.

Set the number of workers for preforking mode.
This is the base for easy and safe concurrency in your app. More workers
you add, more concurrent requests you can manage.
Each worker corresponds to a system process, so it consumes memory,
choose carefully the right number. You can easily drop your system to
its knees by setting a too high value.
Setting workers to a ridiculously high number will not magically make your application web scale – quite the contrary.

没记错的话这个选项应该是CPU数量+1。你可以试著调整一下子进程数量


根据我的经验,你犯的错误是没有用一台单独的伺服器来运行PostgreSQL。


Django 这个框架太慢了,可以尝试著换别的试试。至于uwsgi,个人感觉在单核机器上跑64worker这个明显不合理,可以研究一下gevent协程方式抗并发。
如果你说的64个子进程指的是os的进程的话,1核CPU,不卡才怪。worker进程最好跟CPU核数一致,至少不要超得太多。如果设置方面没问题的话,你得从优化程序架构方面入手了,先找出瓶颈,再针对性地优化。另外,推荐用gevent这种协程来做wsgi的server,相对而言,资源消耗要小得多。
对那些架构不懂,我感觉是不是用的组件太多了?会造成一些不必要的运算,而耗费CPU?另外,你的进程也太多了吧?--我只能让更多的人看到这个问题了。@vczh


推荐阅读:
相关文章