This is an experiment of this earthly world rather than a heavenly or spiritual one. Apache is a popular web server eventhough it can’t solve the C10k Problem.
Prefork (Module Identifier:mpm_prefork_module) is the default Multi Processing Module for Apache Server in Ubuntu.
This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server. Each server process may answer incoming requests, and a parent process manages the size of the server pool.
The other MPMs are Event and Worker (there are others of course: mpm_netware, mpm_os2, mpm_winnt). Visit Apache Module Index to find out more.
I’ve written a How to install a local Ubuntu Server post explaining how I set up a testing server. Now, I am going to use that server for the following experiments.
PHP is loaded as Module by default. Log into your fresh server (described in the above linked article), and run the
Next enable highlighting by pressing
z. Then enable column highlighting by pressing
x. You can change the sorting of the rows by columns. Just press
> until you get the required column highlighted. The above figure shows the rows as ordered by ‘Resident Memory (RE)’ they consume. The most Resident Memory consuming process is the
mysqld. This is the MySQL daemon, accounting for 33Mbs out of total 1GB RAM.
PID: 1668 is the Apache2 parent process owned by root. It consumes 7Mbs of RAM. Each of the children of Apache2 parent process consumes ~ 4.4Mbs of RAM. But 1MB of RAM is being shared.
How the server decided to spawn 9 children? Let’s see the apache2 configuration files stored in ‘/etc/apache2/’.
1 2 3 4 5 6 7 8 9 10 11 12 13
By default, apache2 starts only 5 child processes(StartServers). I simulated a high traffic scenario using Apache Benchmarking tool (ab). As a resulf of the high traffic, Apache2 increased the number of processes to 9. Next, I restarted the server using
sudo service apache2 restart. Then the number of child processes shown was 5. You can change the parameters under
mpm_prefork_module to match your client needs and wants.
Next I changed ‘Start’, ‘Min’ and ‘Max’ servers to 1. I even chaged ‘MaxClients’ to 1. I need to run only one apache2 child. See the
top output for one apache2 child process (PID: 4227).
Benchmarking Apache Performance with Varing number of Child Processes
Let’s benchmark the performance of Apache with One Child and Five Children with
mod_php enabled. We serve a simple html file.
1 2 3 4
First, change the Prefork configuration to run only one child as described above.
ab -n 1000 -c 10 -g one-child.dat http://192.168.1.8/
Then change Apache Prefork to span five children.
ab -n 1000 -c 10 -g five-children.dat http://192.168.1.8/
Then plot the graph. We’ll be using Gnuplot for plotting. Create the Prefork.p
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Now plot the data using
The following is the plot when the concurrecy level is set to 100 (use -c 100 instead -c 10 in ab tool).
Now you have the basic building blocks of Apache2 benchmarking. You can tweak various parameters, collect data and plot. Observe the plot. Contemplate or even meditate on the data and the visualization of the data. Gnuplot can plot more than two datasets. Infact, it is capable of plotting in 3D. It is also used as a plotting engine by third-party applications like Octave.
Gnuplot was originally created to allow scientists and students to visualize mathematical functions and data interactively, but has grown to support many non-interactive uses such as web scripting.
Relaxation of ‘one-per-second’ Rule - Apache2 Process Creation
As of Apache 1.3, the code will relax the one-per-second rule. It will spawn one, wait a second, then spawn two, wait a second, then spawn four, and it will continue exponentially until it is spawning 32 children per second. It will stop whenever it satisfies the MinSpareServers setting. Read more about Apache2 Performance Tuning.
Happy Apache2 Prefork Benchmarking with or without