Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置Python WSGIDaemon--ElasticBeanstalk配置中的最大请求值_Python_Python 3.x_Amazon Web Services_Amazon Elastic Beanstalk_Wsgi - Fatal编程技术网

设置Python WSGIDaemon--ElasticBeanstalk配置中的最大请求值

设置Python WSGIDaemon--ElasticBeanstalk配置中的最大请求值,python,python-3.x,amazon-web-services,amazon-elastic-beanstalk,wsgi,Python,Python 3.x,Amazon Web Services,Amazon Elastic Beanstalk,Wsgi,我正在寻找有关如何在运行Django的AWS ElasticBeanstalk Python环境中设置--maximum requests值的说明。请注意,此环境不使用Linux 2映像,因此gunicorn不是选项,也不使用procfile 最大请求数=nnn定义了对请求数的限制 守护进程应在关闭和重新启动之前进行处理 这可能用于定期强制重新启动WSGI应用程序 处理与Python对象引用相关的问题 计数周期,或不正确使用内存缓存,导致 持续的记忆增长 如果此选项未定义或定义为0,则守护进程

我正在寻找有关如何在运行Django的AWS ElasticBeanstalk Python环境中设置
--maximum requests
值的说明。请注意,此环境不使用Linux 2映像,因此gunicorn不是选项,也不使用procfile

最大请求数=nnn定义了对请求数的限制 守护进程应在关闭和重新启动之前进行处理

这可能用于定期强制重新启动WSGI应用程序 处理与Python对象引用相关的问题 计数周期,或不正确使用内存缓存,导致 持续的记忆增长

如果此选项未定义或定义为0,则守护进程 进程将是持久的,并将继续为请求提供服务,直到 Apache本身被重新启动或关闭

避免在处理请求的站点上将此设置为较低的请求数 交通很拥挤。这是因为不断的重新启动和 重新加载WSGI应用程序可能会导致不必要的负载 影响系统和性能。仅当您没有此选项时才使用此选项 由于内存使用问题而导致的其他选择。尽快停止使用它 内存问题已经解决

您可以将优雅超时选项与此选项结合使用 选项,以减少激活请求的可能性 由于使用此选项而重新启动时中断


您必须替换使用WSGIDaemonProcess指令的Apache服务器配置

SSH到运行elastic beanstalk应用程序的EC2实例,并更改到配置目录
/etc/httpd/conf.d/

在那里查找包含
WSGIDaemonProcess
的文件

grep -rnwl . -e 'WSGIDaemonProcess'
替换elasticbeanstalk应用程序配置中匹配文件的内容

使用shell命令可以方便地获取生成配置的位置(在应用程序部署的过渡阶段):

/opt/elasticbeanstalk/bin/get config container-k wsgi\u staging\u config
.ebextensions/wsgi.config

文件:
/opt/elasticbeanstalk/hooks/appdeploy/pre/05_wsgi.sh:
模式:“000755”
所有者:root
组:根
内容:|
#!/usr/bin/env bash
#在生成的wsgi.conf中设置最大请求选项
sed-i-e'/WSGIDaemonProcess wsgi/a\
\\最大请求数=1000\\
“$(/opt/elasticbeanstalk/bin/get config container-k wsgi_staging_config)

为了实现这一点,我必须在.ebextensions文件夹中创建一个配置,其中包含以下内容

您需要从服务器复制wsgi.conf文件,以确保您首先具有正确的EB设置

files:
  "/opt/elasticbeanstalk/local/override_wsgi_conf.py":
    mode: "000755"
    owner: root
    group: root
    content: |
        #!/usr/bin/env python
        import os
        import sys
        sys.path.append(os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
        import config
    
        MY_APACHE_TEMPLATE = r'''
        # Customized wsgi.conf.  If you're seeing this, good!
 
        LoadModule wsgi_module modules/mod_wsgi.so
        WSGIPythonHome /opt/python/run/baselinenv
        WSGISocketPrefix run/wsgi
        WSGIRestrictEmbedded On

        <VirtualHost *:80>

        Alias /static/ /opt/python/current/app/static/
        <Directory /opt/python/current/app/static/>
        Order allow,deny
        Allow from all
        </Directory>


        WSGIScriptAlias / /opt/python/current/app/key_collector_backend/wsgi.py


        <Directory /opt/python/current/app/>
        Require all granted
        </Directory>

        WSGIDaemonProcess wsgi processes=3 threads=20 maximum-requests=10000 display-name=%{GROUP} \
        python-home=/opt/python/run/venv/ \
        python-path=/opt/python/current/app user=wsgi group=wsgi \
        home=/opt/python/current/app
        WSGIProcessGroup wsgi
        </VirtualHost>

        LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

        WSGIPassAuthorization On
        WSGIApplicationGroup %{GLOBAL}

        '''


        def main():
            try:
                WSGI_STAGING_CONFIG = config.get_container_config('wsgi_staging_config')
                print 'Overriding WSGI configuration in %s' % WSGI_STAGING_CONFIG
                open(WSGI_STAGING_CONFIG, 'w').write(MY_APACHE_TEMPLATE)
            except Exception, e:
                config.emit_error_event(config.USER_ERROR_MESSAGES['badappconfig'])
                config.diagnostic("Error generating config during configdeploy/pre: %s"
                                    % str(e))
                sys.exit(1)
    
    
        if __name__ == '__main__':
            config.configure_stdout_logger()
            main()
 
commands:
 
  5_app_deploy_dir:
    command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/pre"
  5_config_deploy_dir:
    command: "mkdir -p /opt/elasticbeanstalk/hooks/configdeploy/pre"
 
  10_app_deploy_file:
    command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/appdeploy/pre/90_override_wsgi_conf.py"
 
  20_config_deploy_file:
    command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/configdeploy/pre/90_override_wsgi_conf.py"
文件:
“/opt/elasticbeanstalk/local/override_wsgi_conf.py”:
模式:“000755”
所有者:root
组:根
内容:|
#!/usr/bin/env python
导入操作系统
导入系统
sys.path.append(os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(_u文件__zz; zz;))))
导入配置
我的APACHE模板=r''
#自定义wsgi.conf。如果你看到了,很好!
LoadModule wsgi_modules/mod_wsgi.so
WSGIPythonHome/opt/python/run/baselinenv
WSGISocketPrefix运行/wsgi
WSGirestricton嵌入式
别名/static//opt/python/current/app/static/
命令允许,拒绝
通融
WSGIScriptAlias//opt/python/current/app/key\u collector\u backend/wsgi.py
要求所有授权
WSGIDaemonProcess wsgi PROCESS=3个线程=20个最大请求=10000个显示名称=%{GROUP}\
python home=/opt/python/run/venv/\
python路径=/opt/python/current/app user=wsgi组=wsgi\
home=/opt/python/current/app
WSGIProcessGroup wsgi
日志格式“%h(%{X-Forwarded-For}i)%l%u%t\%r\“%>s%b\“%{Referer}i\”\“%{User-Agent}i\”组合
WSGIPassAuthorization On
WSGIApplicationGroup%{GLOBAL}
'''
def main():
尝试:
WSGI_STAGING_CONFIG=CONFIG.get_container_CONFIG('WSGI_STAGING_CONFIG'))
打印“覆盖%s中的WSGI配置”%WSGI\u STAGING\u CONFIG
打开(WSGI_STAGING_CONFIG,'w')。写入(MY_APACHE_模板)
除例外情况外,e:
config.emit_error_事件(config.USER_error_消息['badappconfig'])
config.diagnostic(“在configdeploy/pre期间生成配置时出错:%s”
%str(e))
系统出口(1)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
config.configure_stdout_logger()
main()
命令:
5应用程序部署目录:
命令:“mkdir-p/opt/elasticbeanstalk/hooks/appdeploy/pre”
5\u配置\u部署\u目录:
命令:“mkdir-p/opt/elasticbeanstalk/hooks/configdeploy/pre”
10\u应用程序\u部署\u文件:
命令:“cp-p/opt/elasticbeanstalk/local/override_wsgi_conf.py/opt/elasticbeanstalk/hooks/appdeploy/pre/90_override_wsgi_conf.py”
20\u配置\u部署\u文件:
命令:“cp-p/opt/elasticbeanstalk/local/override_wsgi_conf.py/opt/elasticbeanstalk/hooks/configdeploy/pre/90_override_wsgi_conf.py”
有关详细信息,请参阅此线程。

您如何运行WSGI守护进程?添加一些配置/代码以显示正在运行的内容。我有一个EB项目通过supervisord运行uwsgi,该项目在流程启动时通过
max requests
。我想象你会做类似的事情。我相信EB正在运行这个。我没有做任何事情来启动WSGI守护进程。什么配置文件会有帮助?通常,如果您在EB中运行django,您会使用docker来构建应用程序。现在您说您没有使用Linux2平台,因此了解您如何构建应用程序&runnin会很有帮助