1

Nginx documentation suggests setting worker process to auto for creating one process per core and each process contains one thread. Since context switching is expensive for processes & cheaper for threads, why doesn't Nginx create one worker process in total to hold 1 thread per core in the starting?

Vishal
  • 111
  • 6
  • I think you're splitting hairs here. All Nginx is doing is spinning up enough processes to attempt to saturate the hardware, if the load demands it. How those processes are allocated is the concern of the OS, and in-part, the CPU these days. Context switching on CPU cores is happening nearly constantly, and the number of worker processes isn't going to meaningfully change that. Thousands of threads (and by this, I mean threads... not a CPU unit of threading) could be running at any given time. – Brad Jul 06 '23 at 07:05
  • @RichardSmith Yeah thats the article that inspired the question. They mention worker processes having 1 thread each. – Vishal Jul 06 '23 at 13:58
  • @RichardSmith Obviously I know its non-blocking which brings me back to the question of why Nginx does not opt for 1 process with n worker threads if like you said "context switching for threads may be cheaper than processes". – Vishal Jul 07 '23 at 13:05
  • 1
    @RichardSmith You can fill multiple non-blocking threads in a single process. You are wrong about "You NEED multiple processes to fill up cores". Threads from a single process can fill up cores just fine. Check out this qs: https://stackoverflow.com/questions/60694850/can-the-threads-of-the-same-process-run-on-different-core. I think there is some fine detail that neither of us know. Lets hope someone answers. – Vishal Jul 09 '23 at 08:05
  • Thanks for the link. I now understand your question. – Richard Smith Jul 09 '23 at 08:24

0 Answers0