wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Apache MPM – Worker and Prefork

by | Apr 2, 2010

Apache is a powerful and flexible webserver, that has a very modular architecture. Apache version 2 ports even the basic functionality of a web-server, such as binding to network ports on the machine, accepting requests, and dispatching children to handle the requests to a module named Multi-Processing Module (MPM).

Using a modular approach even for this basic operation, makes Apache portable to a wider variety of Operating Systems. It also adds to the flexibility in using the Module that is apt for the scenario.

MPMs are modules that are chosen during configuration, and compiled into the server, and hence can be changed by a re-compilation, as and when the need arises.

Choosing the right MPM is important in building high performance web servers. In Bobcares web server management services, we analyze the business priority (ie. if security is higher priority or performance), and create a web configuration ideal for the job. Today, we’ll go through the basics of processes and threads, and then briefly cover the popular MPMs Worker and Prefork.

Threads vs. Processes

A process is usually defined as an instance of a program that is being executed, including all variables and other information describing the program’s state. Each process is executed in it’s separate address space.

Processes have a life cycle. They are spawned, they fork newer child processes and eventually die. Each process is an independent entity to which resources are allocated(say memory).

Threads can be called “units of execution”. A process can be thought of as a thread, plus an address space, file descriptors, and a bunch of other data.

A single process might have multiple threads, and all threads within a process share the same state and same memory space, and can communicate with each other directly, because they share the same variables.

Prefork

The Prefork MPM implements a non-threaded, pre-forking web server. A single process launches child processes which listen for connections and serve them when they arrive. Each time a request arrives, the web-server serves the request with a process that is dedicated for that particular request.

If a spare web-server process is not readily present to process an incoming request, a new child process is spawned. The method imparts a lot of stability because each server runs in its own process. If a process dies/or is killed it will not affect other processes, and hence new requests could still be served.

Worker

The Worker MPM implements a hybrid multi-process multi-threaded server. Here, threads serve requests instead of processes. Hence it is able to serve a large number of requests with fewer system resources than a process-based server.

Remember, threads use very little resource when compared to a process.

Since it is not a fully threaded version, it retains much of the stability of a process-based server by maintaining multiple processes, each comprising of numerous threads(like a tree structure – with processes as branches and threads as the leaves).

Which one to choose

If you want all the available server resource put to the best use and get the best performance out of your server, you could switch to worker from the default prefork.

If you would rate stability more, then you would rather prefer prefork to worker.

The decision actually is not that obvious. It warrants expertise, and in-depth analysis of your exact requirements.

Even though other web-servers are making inroads into Apache’s market share, Apache is still the pick, since it has a lot of brains behind it…

Above all, it has a lot of open eyes.. looking through it, and taking care of it always!


About the Author :

Sankar works as a Senior Software Engineer in Bobcares. He joined Bobcares back in April 2006. He loves grooming/mentoring people. During his free time, he listens to music, and enjoys singing..


0 Comments

Categories

Tags