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