Master-worker architecture
Who owns the work?
The master process coordinates configuration and child processes; workers serve connections. In the usual Unix master/worker mode, each worker is a separate process with its own address space. Two workers do not mean two clients maximum: a worker can interleave many connections. Cache manager and loader are auxiliary roles in a configured disk-cache deployment, not mandatory request handlers. The drawing shows roles, not a process tree captured from a machine.
master├── worker A → client connections├── worker B → client connections└── cache helpers (when configured)Create a small, isolated server
For the lab, use two workers and a modest connection allowance. The main context selects the process count; the events block controls connection processing. The HTTP listener belongs only to loopback. The response includes the serving worker PID, which is deliberately variable. Do not infer balanced scheduling from a few requests. The full lab includes its own log, PID and temporary paths. This partial configuration illustrates those decisions.
worker_processes 2;events { worker_connections 128; }http { server { listen 127.0.0.1:19441; location = /who { return 200 "worker=$pid\n"; } }}Reload without replacing the master
On a successful reload the master prepares the new configuration and starts workers for it. Earlier workers cease accepting new connections and drain their outstanding work. Old and new worker generations can overlap. If the master cannot apply the configuration it keeps serving the previous one. Syntax testing is a preflight, not a guarantee of application success. Run these commands only inside a dedicated lab directory; inspect the response and logs after reload. A failed configuration test means stop and fix it, not reload anyway.
nginx -t -p "$PWD/" -c nginx.conf && nginx -p "$PWD/" -c nginx.conf -s reloadcurl --max-time 3 http://127.0.0.1:19441/whoWorker-local and shared state
Separate process memory means a plain module-level counter in one worker is not a global count. Features with explicit shared zones can coordinate selected state across workers; their data structures and synchronization are implementation-specific. A zone is not a distributed cache or database. In this invented snapshot each worker has accepted 3 and 5 requests respectively; an observer who reads only worker A sees 3, not 8. During reload, do not assume arbitrary module state survives. Use a documented shared-state mechanism or an external service for the required lifetime.
worker A local count: 3worker B local count: 5combined observation: 8shared zone: separate explicitly managed statePractice and recap
Draw generations A and B during a successful reload while A handles an existing request. Identify the owner of the PID file and explain why two worker-local counters differ. Check your reasoning against the manual exercise. Next: Event loop and connection handling.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Master-worker architecture
Explain process ownership and shared resources
Which process normally serves HTTP connections?
What happens to old workers after a successful reload?
What does a worker PID in a response establish?
What is true of a normal worker-local counter?
Why check syntax before reload?