Skip to content

Commit 9c73e3a

Browse files
committed
根据pod的limit cpu资源自适配worker数量
1 parent 0e418c6 commit 9c73e3a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

install/docker/entrypoint.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ elif [ "$STAGE" = "dev" ]; then
4141
elif [ "$STAGE" = "prod" ]; then
4242
export FLASK_APP=myapp:app
4343
python myapp/check_tables.py
44-
gunicorn --bind 0.0.0.0:80 --workers 20 --worker-class=gevent --timeout 300 --limit-request-line 0 --limit-request-field_size 0 --log-level=info myapp:app
44+
# 默认worker数量为20
45+
WORKERS_NUMS=20
46+
# 根据是否配置了pod的resource.limits.cpu资源动态调整workers的数量
47+
if [[ $(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us) -ne -1 ]]; then
48+
# IO密集型,worker数量等于resource.limits.cpu核心数量*2+1,如果分配小于一个核心,等于1
49+
WORKERS_NUMS=$(($(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)/$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)*2+1))
50+
fi
51+
# gunicorn方式启动,将错误与访问日志输出到容终端
52+
gunicorn --bind 0.0.0.0:80 --workers ${WORKERS_NUMS} --worker-class=gevent --timeout 300 --limit-request-line 0 --limit-request-field_size 0 --access-logfile=- --error-logfile=- --log-level=info myapp:app
4553
else
4654
myapp --help
4755
fi

0 commit comments

Comments
 (0)