From 5ae50e4e54f64c68385270ceb0107ddb1f4285f9 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sat, 5 Jan 2019 14:53:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20gunicorn=20=E5=92=8C=20cel?= =?UTF-8?q?ery=20=E7=9A=84=20worker=20=E6=95=B0=E9=87=8F=EF=BC=8C=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E6=98=AF=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/entrypoint.sh | 9 +++++++++ deploy/supervisord.conf | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh index 87ed1e61..627c75a5 100755 --- a/deploy/entrypoint.sh +++ b/deploy/entrypoint.sh @@ -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" {} \; diff --git a/deploy/supervisord.conf b/deploy/supervisord.conf index 1b946993..0eca7211 100644 --- a/deploy/supervisord.conf +++ b/deploy/supervisord.conf @@ -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