apache 使用 FastCGI 或 mod_python 运行 Django
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/245237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Django with FastCGI or with mod_python
提问by daniels
which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?
你会推荐哪个?哪个更快,更可靠?apache mod_python 还是 nginx/lighttpd FastCGI?
回答by James Bennett
I've done both, and Apache/mod_python tended to be easier to work with and more stable. But these days I've jumped over to Apache/mod_wsgi, which is everything I've ever wanted and more:
我已经完成了这两项工作,而且 Apache/mod_python 往往更易于使用且更稳定。但是这些天我已经跳到了 Apache/mod_wsgi,这是我想要的一切,甚至更多:
- Easy management of daemon processes.
- As a result, muchbetter process isolation (running multiple sites in the same Apache config with mod_python almost always ends in trouble -- environment variables and C extensions leak across sites when you do that).
- Easy code reloads (set it up right and you can just touch the
.wsgifile to reload instead of restarting Apache). - More predictable resource usage. With mod_python, a given Apache child process' memory use can jump around a lot. With mod_wsgi it's pretty stable: once everything's loaded, you know that's how much memory it'll use.
- 轻松管理守护进程。
- 其结果是,很多更好的进程隔离(运行在同一个Apache的配置多个站点,mod_python的几乎总是麻烦两端-环境变量和C扩展跨站点泄漏当你这样做)。
- 轻松的代码重新加载(正确设置,您只需触摸
.wsgi文件即可重新加载而不是重新启动 Apache)。 - 更可预测的资源使用。使用 mod_python,给定的 Apache 子进程的内存使用可以跳很多。使用 mod_wsgi 它非常稳定:一旦加载了所有内容,您就会知道它将使用多少内存。
回答by bmdhacks
lighttpd with FastCGI will be nominally faster, but really the time it takes to run your python code and any database hits it does is going to absolutely dwarf any performance benefit you get between web servers.
带有 FastCGI 的 lighttpd 名义上会更快,但实际上运行你的 python 代码和它所做的任何数据库访问所花费的时间将绝对使你在 Web 服务器之间获得的任何性能优势相形见绌。
mod_python and apache will give you a bit more flexibility feature-wise if you want to write code outside of django that does stuff like digest auth, or any fancy HTTP header getting/setting. Perhaps you want to use other builtin features of apache such as mod_rewrite.
如果您想在 django 之外编写代码来执行摘要身份验证或任何花哨的 HTTP 标头获取/设置等操作,mod_python 和 apache 将在功能方面为您提供更多灵活性。也许您想使用 apache 的其他内置功能,例如 mod_rewrite。
If memory is a concern, staying away form apache/mod_python will help a lot. Apache tends to use a lot of RAM, and the mod_python code that glues into all of the apache functionality occupies a lot of memory-space as well. Not to mention the multiprocess nature of apache tends to eat up more RAM, as each process grows to the size of it's most intensive request.
如果内存是一个问题,远离 apache/mod_python 会有很大帮助。Apache 倾向于使用大量 RAM,并且与所有 Apache 功能结合的 mod_python 代码也占用大量内存空间。更不用说 apache 的多进程特性往往会占用更多 RAM,因为每个进程都增长到其最密集请求的大小。
回答by Lucky
Nginx with mod_wsgi
带有 mod_wsgi 的 Nginx
回答by dan mackinlay
I'd recommend WSGI configurations; I keep meaning to ditch apache, but there is always some legacy app on the server that seems to require it. Additionally, the WSGI app ecology is very diverse, and it allows neat tricks such as daisy-chaining WSGI "middleware" between the server and the app.
我推荐 WSGI 配置;我一直想放弃 apache,但服务器上总有一些遗留应用程序似乎需要它。此外,WSGI 应用程序生态非常多样化,它允许巧妙的技巧,例如在服务器和应用程序之间建立菊花链 WSGI“中间件”。
However, there are currently known issues with some apps and apache mod_wsgi, particularly some ctypes apps, so be wary if you are trying to run, say, geodjangowhich uses ctypes extensively. I'm currently working around those issues by going back to fastcgi myself.
但是,目前某些应用程序和 apache mod_wsgi存在已知问题,尤其是某些 ctypes 应用程序,因此如果您尝试运行(例如)广泛使用 ctypes 的geodjango,请务必小心。我目前正在通过自己回到 fastcgi 来解决这些问题。
回答by Javier
I'm using it with nginx. not sure if it's really faster, but certainly less RAM/CPU load. Also it's easier to run several Django processes and have nginx map each URL prefix to a different socket. still not taking full advantage of nginx's memcached module, but first tests show hugespeed advantage.
我正在将它与 nginx 一起使用。不确定它是否真的更快,但肯定会减少 RAM/CPU 负载。此外,运行多个 Django 进程并让 nginx 将每个 URL 前缀映射到不同的套接字也更容易。仍然没有充分利用 nginx 的 memcached 模块,但第一次测试显示出巨大的速度优势。
回答by Urkonn
There's also mod_wsgi, it seems to be faster than mod_python and the daemon mode operates similar to FastCGI
还有mod_wsgi,好像比mod_python快,daemon模式和FastCGI类似
回答by Jon Cage
Personally I've had it working with FastCGI for some time now (6 months or so) and the response times 'seem' quicker when loading a page that way vs mod___python. The critical reason for me though is that I couldn't see an obvious way to do multiple sites from the same apache / mod_python install whereas FastCGI was a relative no-brainer.
就我个人而言,我已经将它与 FastCGI 一起使用了一段时间(6 个月左右),与 mod___python 相比,以这种方式加载页面时,响应时间“似乎”更快。不过对我来说,关键的原因是我看不到从同一个 apache / mod_python 安装中执行多个站点的明显方法,而 FastCGI 是一个相对简单的方法。
I've not conducted any particularly thorough experiments though :-)
不过我还没有进行任何特别彻底的实验:-)
[Edit]Speaking from experience though, setting up FastCGI can be a bit of a pain the first time around. I keep meaning to write a guide..!
[编辑]从经验上讲,第一次设置 FastCGI 可能有点痛苦。我一直想写一个指南..!

