history of Nginx
Grzegorz Nosek
grzegorz.nosek at gmail.com
Wed May 7 14:58:48 MSD 2008
On Wed, May 07, 2008 at 12:32:38PM +0200, Manlio Perillo wrote:
> What are the difference between the Apache and Nginx multiprocess model?
>
> Nginx used a master process and all the worker call accept on the same
> sockets.
>
> But what about Apache?
I feel sort of qualified to answer :)
Apache uses a 1:1 relation between processed requests and execution
threads (where "threads" may well be standard Unix processes, and that
was actually the only way before Apache 2.0; read "threads or processes"
when you see "threads" further down).
OK, not exactly 1:1, as Apache keeps a pool of spare threads and the
threads themselves live much longer than connections.
Since Apache 2.0 the details of process model are delegated to a module
called "MPM" (multiprocessing model, IIRC). The most popular are
mpm_prefork (simple fork()) and mpm_worker (two-tiered architecture with
a bunch of processes, each having a number of pthreads). More exotic MPMs
include e.g. mpm_perchild (workers running under different uids, passing
FDs between each other) or mpm_event.
The Apache model has an advantage of simplicity as e.g. nothing prevents
you from blocking or sleeping in handlers but in incurs a much bigger
overhead, especially regarding memory usage.
As for accepting connections, it works more or less the same in Apache
(threads sleeping on a single accept mutex).
> Do you have considered corutines?
> There are some libraries that implement coroutines in C, using POSIX
> setcontext, longjmp or custom ASM code.
>
> As an example one librery with a nice API:
> http://xmailserver.org/pcl.html
Me personally, I find coroutines hard to wrap my mind around and I
actually prefer the nginx "horde of callbacks" model.
Best regards,
Grzegorz Nosek
More information about the nginx
mailing list