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

Most upvoted comments

It’s probably obvious to most people, but if anyone else ends up here wondering what problem 30-tune-worker-processes.sh is 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_AUTOTUNE so 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. 😃