Django 的 Apache 配置性能
我在标准 webfaction 计划(256mb ram)上有一个 Django 项目。我的网站的平均加载时间约为 4 秒。我配置了有关 Django 的大部分性能调整(缓存、压缩、提供静态文件......)。所以我只对 Apache 配置的改进感兴趣。在具有 200kb 数据的网站上加载时间为 4 秒,需要大约 15 个请求才能加载,这是 webfaction 的限制还是我可以显着改善这一点?这就是我的 httpd.conf 现在的样子:
ServerRoot "/home/XXXXXX/webapps/XXXXXX/apache2"
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
#LoadModule headers_module modules/mod_headers.so
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
KeepAlive Off
Listen 28010
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 15
WSGIDaemonProcess XXXX processes=15 python-path=/.../lib/python2.6 threads=8
WSGIPythonPath /home/XXXX/webapps/XXXXX:/home/XXXX/webapps/XXXXXX/lib/python2.6
WSGIScriptAlias / /home/XXXXXX/webapps/XXXXXX/XXXXXX.wsgi
像 KeepAlive On 这样的东西会提高性能吗? 预先感谢霍达什
I have a single Django-project on standard webfaction plan (256mb ram). The average loading time of my website is about 4 seconds. I configured most of the performance tweaks regarding Django (caching, compression, serving static files ...). So I'm only interested in improvements of the Apache configuration. Is 4 sec loading time on a website with 200kb of data, needing about 15 request to load, the limit with webfaction or can I improve this significantly? This is what my httpd.conf looks like right now:
ServerRoot "/home/XXXXXX/webapps/XXXXXX/apache2"
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
#LoadModule headers_module modules/mod_headers.so
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
KeepAlive Off
Listen 28010
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 15
WSGIDaemonProcess XXXX processes=15 python-path=/.../lib/python2.6 threads=8
WSGIPythonPath /home/XXXX/webapps/XXXXX:/home/XXXX/webapps/XXXXXX/lib/python2.6
WSGIScriptAlias / /home/XXXXXX/webapps/XXXXXX/XXXXXX.wsgi
Does something like KeepAlive On increase the performance?
Thanks in advance horndash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不,不。 KeepAlive 和 Django 不能很好地协同工作。 此处引用 Django 书籍:
关闭 Keep -Alive
Keep-alive是HTTP的一个特性,允许多个HTTP请求通过单个 TCP 连接提供服务,避免 TCP 设置/拆卸开销。
乍一看这听起来不错,但实际上会降低 Django 站点的性能。如果您正确地从单独的服务器提供媒体服务,则每个浏览您网站的用户实际上最多每 10 秒只能从您的 Django 服务器访问一个页面。这使得 HTTP 服务器等待下一个保持活动请求,并且空闲的 HTTP 服务器只会消耗活动服务器应该使用的 RAM。
No, no, no. KeepAlive and Django do not play well together. To quote from the Django book here:
Turn off Keep-Alive
Keep-alive is a feature of HTTP that allows multiple HTTP requests to be served over a single TCP connection, avoiding the TCP setup/teardown overhead.
This sounds good at first glance, but can actually kill performance of a Django site. If you’re properly serving media from a separate server, each user browsing your site will actually only a page from your Django server every 10 seconds at best. This leaves HTTP servers waiting around for the next keep-alive request, and a idle HTTP server just consumes RAM that an active one should be using.