Книга: Fedora™ Unleashed, 2008 edition
Apache
Apache
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 you can convert a $1,000 Dell server into something capable of surviving the Slashdot Effect.
NOTE
Slashdot.org is a popular geek news website that spawned the Slashdot Effect — the 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 disks — if you have more RAM, faster chips, and a high-end network card, you can kick sand in Slashdot's face.
The first target of your tuning should be the httpd.conf
file in /etc/httpd/conf
, as well as the other files in /etc/httpd/conf.d
. The more modules you have loaded, the more load Apache is placing on your server — take 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 are almost certain to need mod_mime
and mod_dir
, and probably also mod_log_config
. The default Apache configuration in Fedora is quite generic, so unless you are willing to sacrifice some functionality you might also need mod_negotiation
(a speed killer if there ever was one), and mod_access
(a notorious problem). It's possible to configure both of those last two modules so that they 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 ensure you leave either mod_deflate
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, it in turn 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 EnableMMAP
directive — it is probably commented out and set to off, so you 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 the speed with which Apache can serve pages is limited only by your bandwidth.
TIP
Some people, when questioned about optimizing Apache, recommend you tweak the HARD_SERVER_LIMIT
in the Apache source code and recompile. Although 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 need to change this directive only if you are hosting a huge site.
The default value, 256, is enough to handle the Slashdot Effect — and if you can handle that, you can handle most things.
- Загрузка модулей Apache
- CHAPTER 17 Apache Web Server Management
- About the Apache Web Server
- Installing the Apache Server
- Starting and Stopping Apache
- Starting the Apache Server Manually
- Controlling Apache with Fedora's service Command
- Controlling Apache with Fedora's chkconfig Command
- Graphic Interface Configuration of Apache
- Configuring Apache for Peak Performance
- Apache Multiprocessing Modules
- Apache Modules