我有一个 Django 设置,在 Ubuntu 14.04 LTS 上使用 Django 1.6.7 和 Postgres 9.3。
在任何给定时间,该站点大约有 250 个同时连接到 PostgreSQL 数据库,该数据库是 2.5GHz 的四核 Xeon E5-2670,具有 16GB 的内存。该特定机器上全天的平均负载约为 20 到 30。
有时,我会在哨兵中收到有关数据库连接超时的电子邮件,我认为启用某种连接池将有助于缓解此问题,并稍微降低数据库的负载。
由于我们使用的是 Django 1.6,因此我们可以使用内置池。但是,当我将 CONN_MAX_AGE 设置为 10 秒或 60 秒时,同时连接的数量几乎立即跳到允许的最大设置(大约是我们通常看到的两倍),并且连接开始被拒绝。
所以,出现什么都原因,连接ARE坚持,但他们不被重用。
这可能是什么原因?
附注。我们还使用带有 --worker-class=eventlet 的 gunicorn。也许这就是我们痛苦的根源?
我目前正在尝试使用 alpine 缩小我们的 docker 镜像之一:
FROM python:2.7-alpine
Run Code Online (Sandbox Code Playgroud)
但是,我在安装 matplotlib.h 时遇到了问题:
EOF
warning: no previously-included files matching '*.pyo' found anywhere in distribution
warning: no previously-included files matching '*.pyd' found anywhere in distribution
numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
compilation terminated.
numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
compilation terminated.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-kCID_8/matplotlib/setup.py", line 383, in <module>
**extra_args
File "/usr/local/lib/python2.7/distutils/core.py", line 111, in setup
_setup_distribution = dist …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 vagrant 上设置一个工作主管/gunicorn/django。当代码发生更改时,我正在使用 python-watchdog 尝试重新启动 gunicorn。
我正在为 gunicorn 使用以下主管配置:
[program:someapp]
environment=PYTHONPATH='/vagrant/libs/unmodified/django-error-capture-middleware/src:/vagrant:/home/vagrant/.virtualenvs/someapp/lib/python2.7/site-packages:/vagrant/wsgi',DJANGO_SETTINGS_MODULE=someapp.settings.vagrant
command=/home/vagrant/.virtualenvs/someapp/bin/gunicorn --bind 0.0.0.0:80 --pid=/home/vagrant/.gunicorn.pid --preload --workers=1 --debug --log-level debug --error-logfile - --access-logfile - vagrant_wsgi:application
user=root
group=root
redirect_stderr=true
stdout_logfile = /vagrant/logs/gunicorn.log
stderr_logfile = /vagrant/logs/gunicorn.log
stdout_logfile_maxbytes=0
autostart=true
autorestart=true
stdout_events_enabled=true
loglevel=debug
Run Code Online (Sandbox Code Playgroud)
这一切都很好。看门狗也工作正常。但是,当我使用看门狗运行 . 时kill -HUP [pidofgunicorn],有时它实际上不会完全重新加载。有时 django 甚至会报告模块在之前存在时丢失(我根本没有修改 sys.path)。
如果我使用看门狗运行一个supervisorctl restart someapp,它工作正常。但是,它需要更长的时间,尤其是在 virtualbox 实例上。
有什么我可以做的让 gunicorn 优雅地重新加载,并实际看到所做的更改?