Book Image

Nginx Essentials

By : Valery Kholodkov, Valery I Kholodkov
Book Image

Nginx Essentials

By: Valery Kholodkov, Valery I Kholodkov

Overview of this book

Table of Contents (13 chapters)

Allocating worker processes


We now consider recommendations on allocating worker processes. First, let's discuss a little bit about the background. Nginx is an asynchronous web server, which means actual input/output operations run asynchronously with the execution of a worker process. Each worker process runs an event loop that fetches all file descriptors that need processing using a special system call, and then services each of these file descriptors using nonblocking I/O operations. Hence, each worker process serves multiple connections.

In this situation, the time between an event occurs on a file descriptor, and this file descriptor can be serviced (that is latency) depends on how soon a full event processing cycle can be completed. Therefore, in order to achieve higher latency it makes sense to penalize the competition for CPU resources between worker processes in favor of more connections per process, because this would reduce the number of context switches between worker processes...