【问题标题】:Django on Apache with FCGI - 500 internal server error under high load带有 FCGI 的 Apache 上的 Django - 高负载下的 500 内部服务器错误
【发布时间】:2012-11-24 12:25:09
【问题描述】:

我使用 Windows Server 2008、Apache 2.2 Python 2.7 和 Django 作为 FCGI 服务器

FCGI 服务器作为 SrvAny 服务启动:


python c:\amebas_site\amoeba\manage.py runfcgi host=127.0.0.1 port=8881 daemonize=True method=threaded outlog=c:\amebas_site\logs\access.log errlog=c:\amebas_site\logs\error.log maxchildren=100 maxspare=90 minspare=50 maxrequests=10 debug=True

我尝试了不同的 maxspare、minspare、maxrequests 和 maxchildren 值,但没有任何帮助。在高负载下,我总是收到“500 服务器错误”。

Apache 配置:

FastCGIExternalServer c:\amebas_site\fcgi.hook -host 127.0.0.1:8881

 RewriteEngine On
 ...
 RewriteCond ${REQUEST_FILENAME} !-f
 RewriteRule ^/(.*)$ /fcgi.hook/$1 [QSA,L]

当有 5-6 个用户在线时,我的 django 网站运行良好,没有错误。 但是当我进行压力测试(通过 loadimpact.com 的 50 个虚拟用户)时,该站点显示“500 个内部服务器错误”页面,并且我在我的 apache 日志中收到一条错误消息:

[Thu Dec 06 16:29:48 2012] [error] [client 54.246.71.7] (OS 10054)An existing connection was forcibly closed by the remote host. : FastCGI: comm with server "C:/amebas_site/fcgi.hook" aborted: read failed [Thu Dec 06 16:29:48 2012] [error] [client 54.246.71.7] FastCGI: incomplete headers (0 bytes) received from server "C:/amebas_site/fcgi.hook"

但是在 Django 日志中有注释。我怎样才能调试这个问题并摆脱它?

【问题讨论】:

    标签: django windows apache fastcgi


    【解决方案1】:

    看,你有 maxchildren=100 1. 如果您的请求超过 1-2 秒(可能在调试中),那么您的服务器无法处理所有 50 个连接 2. 如果你有静态文件并且它是由 django 提供的 - 那么它也使用额外的连接

    解决方案:例如,您可以分析日志并计算 5 秒内有多少请求

    【讨论】:

    • 静态文件由 Apache 提供。当有 50 个虚拟用户时,我每秒有超过 20 个请求。
    • 我会尝试更多的子线程,但我仍然想知道 FCGI 会发生什么。如何确定它是在处理请求的某个地方失败还是只是超时?在测试期间,页面加载时间也从 1 秒增加到 30 秒。
    • 我再次尝试使用 maxthreads=256,但没有帮助,即使只有 25 个连接,仍然会出现故障(500 个内部服务器错误)。
    猜你喜欢
    • 2015-02-12
    • 2016-10-28
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2015-11-22
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多