设置 gunicorn 和 celery 的 worker 数量,最小是 2

This commit is contained in:
virusdefender 2019-01-05 14:53:55 +08:00
parent a52f383930
commit 5ae50e4e54
2 changed files with 11 additions and 2 deletions

View File

@ -37,6 +37,15 @@ else
sed -i "s/__IP_HEADER__/\$remote_addr/g" api_proxy.conf;
fi
if [ -z "$MAX_WORKER_NUM" ]; then
export CPU_CORE_NUM=$(grep -c ^processor /proc/cpuinfo)
if [[ $CPU_CORE_NUM -lt 2 ]]; then
export MAX_WORKER_NUM=2
else
export MAX_WORKER_NUM=$(($CPU_CORE_NUM))
fi
fi
cd $APP/dist
if [ ! -z "$STATIC_CDN_HOST" ]; then
find . -name "*.*" -type f -exec sed -i "s/__STATIC_CDN_HOST__/\/$STATIC_CDN_HOST/g" {} \;

View File

@ -28,7 +28,7 @@ stopwaitsecs = 5
killasgroup=true
[program:gunicorn]
command=sh -c "gunicorn oj.wsgi --user server --group spj -b 127.0.0.1:8080 --reload -w `grep -c ^processor /proc/cpuinfo`"
command=gunicorn oj.wsgi --user server --group spj --bind 127.0.0.1:8080 --workers %(ENV_MAX_WORKER_NUM)s --threads 4 --max-requests-jitter 10000 --max-requests 1000000 --keep-alive 32
directory=/app/
stdout_logfile=/data/log/gunicorn.log
stderr_logfile=/data/log/gunicorn.log
@ -39,7 +39,7 @@ stopwaitsecs = 5
killasgroup=true
[program:celery]
command=celery -A oj worker -l warning
command=celery -A oj worker -l warning --autoscale 2,%(ENV_MAX_WORKER_NUM)s
directory=/app/
user=nobody
stdout_logfile=/data/log/celery.log