Despite being the most popular web server on the Internet, Apache is by no means the fastest. Part of the "problem" is that Apache has been written to follow every applicable standard to the letter, so much of its development work has been geared toward standards-compliancy rather than just serving web pages quickly. That said, with a little tweaking we can convert a $1,000 Dell server into something capable of surviving the Slashdot Effect.
Slashdot.org is a popular geek news website that spawned the Slashdot Effectthe result of thousands of geeks descending on an unsuspecting website simultaneously. Our $1,000 Dell server had dual-2.8GHz Xeons with 1GB of RAM and SCSI hard disksif you have more RAM, faster chips, and a high-end network card you can kick sand in Slashdot's face.
The first target for your tuning should be the httpd.conf file in /etc/apache2, as well as the other files in /etc/apache2. The more modules you have loaded, the more load Apache is placing on your servertake a look through the LoadModule list and comment out (start the line with a #) the ones you do not want. Some of these modules can be uninstalled entirely through the Add or Remove Packages dialog.
As a rough guide, you will almost certainly need mod_mime and mod_dir, and probably also mod_iog_config. The default Apache configuration in Ubuntu is quite generic, so unless you are willing to sacrifice some functionality you may also need mod_negotiation (a speed killer if there ever was one), and mod_access (a notorious problem). Both of those last two modules can and should work with little or no performance decrease, but all too often they get abused and just slow things down.
Whatever you do, when you are disabling modules you should ensure you leave either mod_defiate or mod_gzip enabled, depending on your Apache version. Your bottleneck is almost certainly going to be your bandwidth rather than your processing power, and having one of these two compressing your content will usually turn 10Kb of HTML into 3Kb for supported browsers (most of them).
Next, ensure keepalives are turned off. Yes, you read that right: turn keepalives off. This adds some latency to people viewing your site, because they cannot download multiple files through the same connection. However, in turn it reduces the number of simultaneous open connections and so allows more people to connect.
If you are serving content that does not change, you can take the extreme step of enabling MMAP support. This allows Apache to serve pages directly from RAM without bothering to check whether they have changed, which works wonders for your performance. However, the downside is that when you do change your pages you need to restart Apache. Look for the EnabieMMAP directiveit is probably commented out and set to off, so you will need to remove the comment and set it to on.
Finally, you should do all you can to ensure that your content is static: avoid PHP if you can, avoid databases if you can, and so on. If you know you are going to get hit by a rush of visitors, use plain HTML so that Apache is limited only by your bandwidth for how fast it can serve pages.
Some people, when questioned about optimizing Apache, will recommend you tweak the hard_server_limit in the Apache source code and recompile. While we agree that compiling your own Apache source code is a great way to get a measurable speed boost if you know what you are doing, you should only ever need to change this directive if you are hosting a huge site.
The default value, 256, is enough to handle the Slashdot effect, and if you can handle that then you can handle most things.
Was this article helpful?