在使用gunicorn部署flask项目时,遇到了gunicorn worker数量设置问题。
官方推荐 2n + 1.
Generally we recommend
(2 x $num_cores) + 1
as the number of workers to start off with.
其中 $num_cores 的计算方式:
1.
cat /proc/cpuinfo | grep 'core id' | wc -l
2.
nproc
所以启动脚本可以写成:
gunicorn -w $(( 2 * `cat /proc/cpuinfo | grep 'core id' | wc -l` + 1 )) myapp:wsgi
或者
gunicorn -w $(( 2 * `nproc` + 1 )) myapp:wsgi