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

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

问题描述

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

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.

加载并运行一个(非常)小的站点后,它目前使用 143MB 的 256MB RAM.

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

使用 top 命令我可以看到 Apache 使用了 52.9% 的可用 RAM,第二个 memcache 使用了 2.1%.

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(驻留集大小)内存.在这种情况下,您可以在此处(在内存受限的 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屋!

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