
A few years ago, when I was introduced to Amazon EC2, MicroInstance was launched with Ubuntu 10.04 LTS on board. Apache was raised on it and several virtual hosts were configured, including a MODx Revolution blog. I had a free minute and thought to me what would happen if a crowd of readers suddenly came running into my hidden cloud. In general, there is nowhere to run into it, but the spirit of knowledge, instilled in childhood by repeated viewing of the film magazine “I want to know everything,” did not give rest. I have not had the opportunity to participate in high-load projects so far, so a small study of materials on the network was conducted. The statement that it is necessary to abandon the use of Apache in favor of Nginx is roaming from blog to blog. This statement seemed strange to me, given the history of the Apache project and the community of developers around it. Can Apache developers not be able to solve the problem of the prefork mode being scolded everywhere? Is it really what I decided to find out. Read the results under the cut.
Training
After studying the topic in more detail, it turned out that in addition to the MPM (Multi-Processing Module) prefork, Apache also has mpm-worker and mpm-event modules that process requests from several users in one program flow. The mpm-event and mpm-prefork modules communicate with php via fastcgi. Compare their work with nginx and it was decided.
First of all, I decided to see how Apache behaves in prefork mode with a large number of requests. The siege utility was launched with 40 threads. Apache has created many processes and logs filled with messages about memory overflow. After that, the server became unavailable and had to terminate for this instance, since it was not possible to wait for the reaction for 5 minutes on the reboot. A new instance was created, to which the old ebs was connected. As a result, it was established experimentally that on EC2 MicroInstance with its memory capacity of 630MB, the following settings are optimal:
<IfModule mpm_prefork_module> StartServers 3 MinSpareServers 3 MaxSpareServers 7 MaxClients 27 MaxRequestsPerChild 3000 </IfModule>
Now it was possible to load the server without fear of losing its control.
')
It was decided to test the following configurations:
- apache mpm-prefork with mod_php
- apache mpm-prefork with mod_php + nginx reverse proxy
- nginx with php-fpm
- apache mpm-worker with php-fpm
- apache mpm-event with php-fpm
In the process of testing, the thought came that nothing prevents apache in mpm-prefork mode from working with php-fpm and this configuration has also been added to the tests.
I will not tell you how to install the configurations used in this article, you can easily find this information on the Internet. Let me just note that in many howto the same error is duplicated for a bunch of mpm-worker or mpm-event with php, namely: the package manager commands specify to install the php5 package, in fact it is necessary to install the php5-cgi package.
I was primarily interested in how many requests the web server could handle. Therefore, I decided to use the siege utility for tests. Having experimented with JMeter, I came to the conclusion that it is more suitable for determining the reaction time to certain events. Thus, the main parameter of interest to me from the output of the siege utility results was Availablility. Based on this, the siege utility parameters were selected so that Availability was less than 100%, but not too low. In all tests, the number of streams used was 20 (-c) the number of repetitions was 20 (-r) benchmark mode (-b).
For processing the test results, an Excel file was created, the tables of which entered the results displayed by the siege utility. According to the results of five tests, the arithmetic mean and the mean square error of the arithmetic mean are found. An availability diagram is constructed for different configurations.
A simple script was written that performs the required number of tests and processes the siege output results for copy-paste in Excel:
The parameters of the script are the URL file that was generated from the sitemap, and the number of iterations in the case of these tests was always 5. Sleep 60 is necessary to complete all the queues from the previous iteration.
Along the way, it was decided to attach to the CDN CloudFlare website, and at the same time see how this service affects the load capacity of the webserver. To do this, a subdomain with the direct address of the site was added to the CloudFlare DNS and an alias was added in the virtual host settings. Also another URL file was created for direct access to the site.
results
Detailed test results you can see in this
file . Here I will give only diagrams.
It is not clear why it stands out from the general trend of apache mpm-prefork via CloudFlare.
Since the results obtained had large errors due to the significant variation in the values of each pass, it was decided to conduct an additional test on the local virtual machine. For this purpose, the Ubuntu 10.04 LTS guest system on VirtualBox was created, with parameters identical to EC2 MicroInstance (1vCPU, 630MB, 8GB). To get a similar percentage of failures, I limited the maximum processor load available to a virtual machine at 7% (Intel Core i7 2.8 GHz). Detailed results of this test can be found in this
file .
The ratio of the results is similar to the test through CloudFlare.
findings
- The Apache and Nginx bundle recommended in many manuals as reverse proxy will not deliver the desired result if your site has few static resources.
- Apache can compete successfully with Nginx if you install mpm-worker or mpm-event modules instead of the mpm-prefork module.
- Apache can compete with Nginx even if you use the mpm-prefork module, and you need to use php-fpm via fastcgi.
- If you use the mpm-prefork module, do not forget to limit the number of processes according to the resources of your system.
- Using CDN CloudFlare at a free rate does not give a noticeable increase in load capacity. Plus, we can assume that in case of complete inaccessibility of the site, CloudFlare will display the saved “snapshot” of the requested page.
