Django部署:削减Apache的开销 [英] Django Deployment: Cutting Apache's Overhead

查看:106
本文介绍了Django部署:削减Apache的开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型VPS服务器,它具有一个Nginx前端,它提供静态媒体文件,并将Django请求传回给运行mod_wsgi的Apache 2.2 prefork MPM服务器。



一个(非常)小的网站加载和工作,它目前正在使用143MB的256MB的RAM。



使用顶部命令我可以看到,Apache正在使用52.9%的可用RAM,memcache在第二次使用2.1%。



考虑到我正在计划投入不少Django在这个服务器上进行项目,我想知道是否有任何可以修剪Apache使用的RAM的数量?

解决方案

如果你想坚持使用Apache,几个建议大致按照难度排列:




  • 使用Apache工作器MPM的prefork。每个客户端连接使用的实际内存将会更低,但请注意,在Linux上为Apache分配的虚拟内存可能会显得非常高,因为每个线程的堆栈分配8MB的Linux。这实际上并不重要,除非你的VPS是脑死亡的,而不是虚拟内存,而不是实际的RSS(驻留集大小)内存。在这种情况下,您可以了解如何降低线程堆栈大小此处(下)内存限制的VPS部分)。

  • 编辑您的Apache配置文件,并按比例减少StartServers,MaxClients,MinSpareThreads和MaxSpareThreads设置。相应的级别将在您希望的内存使用量和您需要提供的并发客户端数量之间取得平衡。

  • 切换到 mod_wsgi (在守护进程模式下)而不是mod_python。


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.

With one (very) small site loaded and working, it's currently using 143MB of 256MB of RAM.

Using the top command I can see that Apache is using 52.9% of available RAM, with memcache in second using 2.1%.

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?

解决方案

If you want to stick with Apache, a few suggestions, roughly in order of difficulty:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆