docker-nginx: nginx start can't get cpu limit and change worker_processes numbers
nginx start can’t get cpu limit and change worker_processes numbers. I think you can add follow scripts to docker-entrypoint.sh.
CPU_CFS_QUOTA_US=`cat /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us`
CPU_CFS_PERIOD_US=`cat /sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us`
if [ "$CPU_CFS_PERIOD_US" -ne "-1" ]
then
WORKER_PROCESSES=`awk 'BEGIN{printf "%.2f\n",'''$CPU_CFS_QUOTA_US'''/'''$CPU_CFS_PERIOD_US'''}'|awk '{print int($1+1)}'`
sed -i "s/worker_processes 2/worker_processes $WORKER_PROCESSES/g" /etc/nginx/nginx.conf
fi
add this script,The nginx can start with the worker_processes auto.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 17
Commits related to this issue
- Introduced an entrypoint script to autotune the number of worker processes The script is a no-op bye default, you would need to enable its logic by setting an NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTU... — committed to thresheek/docker-nginx by thresheek 4 years ago
- Introduced an entrypoint script to autotune the number of worker processes The script is a no-op bye default, you would need to enable its logic by setting an NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTU... — committed to thresheek/docker-nginx by thresheek 4 years ago
It’s probably obvious to most people, but if anyone else ends up here wondering what problem
30-tune-worker-processes.shis trying to solve, the penny dropped when I read https://github.com/jitsi/docker-jitsi-meet/pull/853#issuecomment-739574362 (which references this issue).Crucially the issue is that
worker_processes auto(in/etc/nginx/nginx.conf) results in nginx starting the number of worker processes matching the host CPU count, even if the container has limits on how much CPU it can use - so this script tries to account for that and be more conservative.I couldn’t find any documentation re
NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNEso perhaps this would be useful to mention on say https://hub.docker.com/_/nginx?@Darren-wh Yes. That is also what I would like you to test. 😃