ItecSoftware Logo

Apache Prefork Vs Worker Threads

Written by Peter Gilg on - like this:
apache prefork vs worker threads

We often get questions like: What is the difference between Apache Prefork vs Worker Threads? Is it wrong to have set the configuration values the same for both? Or is it wrong to have them different?

In this quick article I will shed some light between the two modules and assess what real world circumstances, a certain os and application would call for which solution.

It all goes back to the old NCSA server where Apache 1 grew up in a UNIX environment. It was a multiprocessing server, where each client would be serviced by one server instance. If there were more concurrent clients than server processes, Apache would fork additional server processes to deal with them. Under normal operation, Apache would preserve a pool of at hand server processes to deal with incoming requests.

Whereas this scheme works well on *NIX-systems, it’s an inefficient solution on platforms such as Windows, where forking a process is an high priced operation. So making Apache truly cross-platform required another solution. The approach adopted for Apache 2 is to turn the core processing into a pluggable module which can be optimized for diverse environments.

Prefork

The Apache Prefork MPM (multi processing module) is a non-threaded model, basically much like Apache 1.x. The threaded model came with version 2.x. It is a safe option in all cases, and for servers running non-thread-safe software such as PHP, it is the only safe option. For some applications, including a myriad of of those favorite with Apache 1.3 (e.g. simple static pages, CGI scripts), the Apache Prefork MPM may be as good as anything.

Keep in mind that on Linux versions, Prefork is commonly reported to be as fast as Worker. On Solaris, Worker is reported to be much faster than Prefork.

Worker Threads

The Apache Worker MPM is the newer, threaded model, whose advantages include lower memory usage which is imperative on busy servers and much greater scalability than that provided by the Prefork version in particular types of applications.

Both of the stable MPM’s suffer from a limitation that affects extremely busy servers. Whereas HTTP keep-alive is essential to decrease TCP association and network overhead, it ties up a server process or thread whilst the keepalive is active. As a consequence, a extremely busy server may run out of at hand threads. A busy server with the Worker MPM may continue tens of thousands of hits per second, as happens with favorite sites such as Facebook or Twitter).

If you like to read up more on the subject, we highly recommend The Apache Modules Book, some excerpts were taken for this article.

Listed in Linux, Web Development

Tags: apache, prefork, web server, worker threads

Leave a Reply

Your email address will not be published. Required fields are marked *