Django的部署:切割Apache的开销 [英] Django Deployment: Cutting Apache's Overhead
问题描述
我有了,可供静态媒体文件,并将Django的请求返回到Apache 2.2 prefork MPM服务器上运行的mod_wsgi Nginx的一个前端的小VPS服务器。
I have a small VPS server that has a Nginx front end that serves up static media files and passes Django requests back to an Apache 2.2 prefork MPM server running mod_wsgi.
一(非常)小网站加载和工作,它是目前使用256MB的RAM 143MB。
With one (very) small site loaded and working, it's currently using 143MB of 256MB of RAM.
使用顶
命令,我可以看到Apache是在第二使用2.1%使用可用RAM的52.9%,其中内存缓存。
Using the top
command I can see that Apache is using 52.9% of available RAM, with memcache in second using 2.1%.
考虑到我计划把相当多的Django项目,这台服务器上,我想知道如果有什么我可以做修剪Apache是否使用的RAM数量?
Considering that I'm planning on putting quite a few Django projects on this one server, I'm wondering if there is anything I can do to trim the amount of RAM that Apache is using?
推荐答案
如果你想与Apache,提几点建议,坚持大致难度顺序:
If you want to stick with Apache, a few suggestions, roughly in order of difficulty:
- 使用Apache的工人的MPM,而不是prefork。每个客户端连接使用的实际内存会更低,但要知道,分配给Linux上的Apache虚拟内存会出现非常高的,由于Linux的8MB分配为每个线程的堆栈。这实际上并不重要,除非你的VPS是脑死亡和帽的虚拟内存,而不是实际的RSS(驻留集大小)内存。在这种情况下,你可以学习如何降低线程堆栈大小 rel=\"nofollow\"> (在内存受限的VPS部分)。
- 编辑您的Apache的配置文件,并减少大致比例StartServers的,MaxClients的,MinSpareThreads和MaxSpareThreads设置。适当的水平将是你想要的内存使用情况,你需要能够满足并发客户端的数量之间的平衡。
- 开关 mod_wsgi的(在守护进程模式),而不是mod_python的。
- use the Apache worker MPM instead of prefork. Real memory used per client connection will be lower, but be aware that the virtual memory allocated for Apache on Linux can appear very high, due to the 8MB Linux allocates for each thread's stack. This doesn't actually matter, unless your VPS is brain-dead and caps virtual memory rather than actual RSS (resident set size) memory. In that case you can learn how to lower the thread stack size here (under the Memory-constrained VPS section).
- edit your Apache config file and reduce the StartServers, MaxClients, MinSpareThreads, and MaxSpareThreads settings roughly in proportion. The appropriate levels will be a balance between your desired memory usage and the number of concurrent clients you need to be able to serve.
- switch to mod_wsgi (in daemon mode) instead of mod_python.
这篇关于Django的部署:切割Apache的开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!