File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,7 +41,15 @@ elif [ "$STAGE" = "dev" ]; then
4141elif [ " $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
4553else
4654 myapp --help
4755fi
You can’t perform that action at this time.
0 commit comments