How to optimize Apache server performance Summary _linux

Source: Internet
Author: User
Tags dedicated server perl script

Testing and improving performance

The Apache server has been designed to be as fast as possible, and even if you use a machine that is not configured with a high configuration, you don't need to make too complex a setup, and its response content is enough to fill up all the previous narrowband connections. But as the content of the site becomes increasingly complex and bandwidth increases, it becomes increasingly important to optimize Apache for better performance.

It's a waste of time if the results of optimization are just minimal performance improvements. Imagine that you spent hours or even days tuning Apache parameters but only a few percent of performance improvement? So the first step you should take before tuning is to test your current server performance to determine how to optimize your server and measure the effectiveness of your optimization.

It's not the first time we've talked about Apache testing (see "Rushing out of the water"), as we mentioned before, it is often difficult to determine which part of the bottleneck is causing the problem, is it because of the setup of Apache itself or the Dynamic Web application environment you are using? About finding out if the problem with the Web site program is beyond the scope of this article, let's talk a little bit about the usual ways to improve the Apache server speed and how it interacts with other components that make up a Web site.

Host Hardware

Apache's machine and operating system environment is the most performance-affecting factor, it is obvious that a 368 pc and a P4 or dual-processor machine will not have the same performance. However, if the hardware changes are not involved, the biggest thing we can do is to first look at whether Apache is running on a dedicated server, and if sharing a server with other applications will certainly affect the performance of the server.

In most cases, goodbyes are a key factor in the performance of a static web site, because it determines how much content Apache can cache. The more content it caches, the less opportunity to read content on your hard disk, and the time it takes to access specific files on your hard disk. If your site is mostly static content, you'd better use the Mod_cache option, if your memory is large enough, you can use the Mod_mem_cache option.

The first option caches information on disk, and it works well when used with the Mod_include option, which saves its final version in the cache when you create a page. Use Mod_mem_cache to save cached content in a memory heap that can be shared by all Apache processes.

Using faster disks or using RAID further can improve Apache access to disk files. Note that if you do all of the following optimizations, a hardware (not software) upgrade scheme is a better choice. The last one talked about hardware is CPU power, which has a great impact on dynamic content sites, the more dynamic content requirements higher.

By extruding every cent of the Apache server's potential, you can make your site more memorable for others, especially for some dynamic websites. This article is mainly about how to optimize the installation and setup of Apache servers, which is also the most controlling part of your work.

testing and improving performance

The Apache server has been designed to be as fast as possible, and even if you use a machine that is not configured with a high configuration, you don't need to make too complex a setup, and its response content is enough to fill up all the previous narrowband connections. But as the content of the site becomes increasingly complex and bandwidth increases, it becomes increasingly important to optimize Apache for better performance.

It's a waste of time if the results of optimization are just minimal performance improvements. Imagine that you spent hours or even days tuning Apache parameters but only a few percent of performance improvement? So the first step you should take before tuning is to test your current server performance to determine how to optimize your server and measure the effectiveness of your optimization.

It's not the first time we've talked about Apache testing (see "Rushing out of the water"), as we mentioned before, it is often difficult to determine which part of the bottleneck is causing the problem, is it because of the setup of Apache itself or the Dynamic Web application environment you are using? About finding out if the problem with the Web site program is beyond the scope of this article, let's talk a little bit about the usual ways to improve the Apache server speed and how it interacts with other components that make up a Web site.

Host Hardware

Apache's machine and operating system environment is the most performance-affecting factor, it is obvious that a 368 pc and a P4 or dual-processor machine will not have the same performance. However, if the hardware changes are not involved, the biggest thing we can do is to first look at whether Apache is running on a dedicated server, and if sharing a server with other applications will certainly affect the performance of the server.

In most cases, goodbyes are a key factor in the performance of a static web site, because it determines how much content Apache can cache. The more content it caches, the less opportunity to read content on your hard disk, and the time it takes to access specific files on your hard disk. If your site is mostly static content, you'd better use the Mod_cache option, if your memory is large enough, you can use the Mod_mem_cache option.

The first option caches information on disk, and it works well when used with the Mod_include option, which saves its final version in the cache when you create a page. Use Mod_mem_cache to save cached content in a memory heap that can be shared by all Apache processes.

Using faster disks or using RAID further can improve Apache access to disk files. Note that if you do all of the following optimizations, a hardware (not software) upgrade scheme is a better choice. The last one talked about hardware is CPU power, which has a great impact on dynamic content sites, the more dynamic content requirements higher.

Server Settings


If your environment has been established Apache has also been optimized, you can view your setup files to take the next step of optimization. A good way to do this is to simplify your setup file by reducing the instructions in the file (directives) to hundreds of lines, first by removing the comment lines and deleting any non-essential content.

Simplifying settings Files

The first step is to simplify the settings settings file, which does not bring any direct performance improvements, but it makes the settings file easier to use to reduce your chances of error.

It is a good idea to start from a default provisioning file before making optimizations. These files are often placed in the Apache settings directory, the file name is Httpd.conf.orig or Httpd-std.conf, do not use a file like performance-std.conf name, in the long run, if you are ready to add a lot of additional settings in the information, it is not a good starting point. On the other hand, if your goal is to build a fast static Web server, this might be the easiest way to get the server running.

If you are familiar with the Apache settings instructions or are willing to browse the Help files, you can remove all the annotation content from the settings file, because they often make the actual instructions difficult to find, you can also remove the current platform on the use of multiprocessor mode (MPM) reference.

Disabling modules

Now that we've got a refreshing setup file, we can start to remove the elements that our system doesn't use, especially the following:

Hostnamelookups (host name lookup), which increases the cost of processing each request, first, the server will do a reverse query to the DNS system to find the host name of the client system, and then make a forward query to see if the host name is true to the client's IP. In most cases, you can simply turn off this feature, and if you do a lot of server logs, this work can be done in the future. You can turn off this feature by adding an indication of hostnamelookups off in the settings file.

Symbolic connections. When this option is turned on, Apache checks whether each request contains a reference to the symbolic connection, which calls the Lstat () system call once for each path contained in the request. Unless you are ready to use the symbolic connection, use options-followsymlinks to turn it off.

Server state information. While this is useful for testing and monitoring servers, it also brings additional overhead to the server, which you can turn off by looking for any instructions like SetHandler server-status, and if possible, you can remove the module when you install Apache.

Use flexible options such as wildcard characters when you can be more precise, for example, for directoryindex instructions, explicitly specify a list of settings files, most commonly used in the first place.

Unless you have a good reason to allow CGI execution, place the CGI file in a specific directory and set the right permissions, which avoids the need for Apache to determine for each request whether a static file or a dynamic file is required.

Disable Log


Writing log information is a time-consuming task, although Apache keeps the log file open to save time to open the file, but it still takes a lot of time. If it is not necessary to store the log information, you can turn off this option to save more processor time, simply by commenting out the log line in the settings file to turn it off.

If you must keep the log, you can turn off the hostnamelookups option (see above) and copy the log file to another machine for further analysis.

simplifying settings at the directory level

htaccess files can greatly extend Apache setup parameters without having to edit the Apache master settings file every time you change the design, but the use of this file also lowers the performance of the server.

If you use this file, Apache must first look in the current directory for the existence of this file, and if so, parse the file and apply the settings in the current directory to the file. Worse, Apache not only wants to see the current directory, but also to see if all the top-level directories in the current directory include htaccess files to finalize the settings based on all these files.

If you want to optimize server performance, you should disallow the use of htaccess files, and any basic directory settings can be made in the main settings file, and the primary settings file is resolved only once when the server is started. In order to disable the htaccess file, add an indication in any section allowoverride None.

multi-processing mode setting

Multi-processing mode (multi-processing module/mpm) he allows a specific platform to handle multiple concurrent connections. MPM modules are platform-dependent and have different solutions for UNIX, Windows, BeOS, and NetWare, and some platforms have more than one solution to choose from. For most users, the default settings for a particular platform already work well, and it is a time-consuming task to fine-tune these parameters. But if you want to maximize the potential of Apache, you have to adjust these settings.

For most platforms, there is only one MPM option, but under UNIX there are two options: Prefork generates multiple identical Apache processes with Worker,prefork mode, and worker mode creates multiple threads. Typically, the Prefork mode works better for systems with only one to two processors, and the threading model works more efficiently for systems with more processors.

In either case, the maxclients indicator is the most effective way to improve server performance, which controls the maximum number of concurrent connections that Apache can handle.

Optimizing static Content


If your Web server uses a lot of static content or you're dealing with dynamic and static content with two Web servers, your main goal now is to shorten the response time for the server to send the requested content, and the easiest way is to use the Mod_cache cache module. You can use Mod_disk_cache and Mod_mem_cache to provide disk-based caching and memory based caching, respectively.

You can view the documentation on the Mod_cache to get further information.

Optimizing dynamic Content

Dynamic content may be the most time-consuming part of all Web servers, especially when using CGI, a simple program can increase the response time by several seconds.

One of the big benefits of using a scripting scenario is that they put an interpreter in Apache, this reduces the time to reload the interpreter during execution, and some scenarios cache the parsed script so that the next time you encounter the same request, you can execute it directly without having to parse it again.

Tuning optimization for a particular system is complex and time-consuming, and you need to adjust specific scripts to take advantage of the results of the optimization.

However, the optimization of dynamic content is very obvious, only to the Perl script execution mode from CGI to Mod_perl can reduce the execution time of up to 70%, if we further, can also use the persistent connection to the database or cache information between multiple requests, This is useful for e-commerce sites, and it also reduces the overhead of repeatedly loading information between different requests.

Summary

Although Apache is a highly customizable, powerful and fairly complex server software, it is interesting to note that even Apache's standard installation can achieve good performance. Adjusting Apache setting parameters is a way to easily significantly improve server performance. Unfortunately, often the most uncontrollable content in Apache--such as the dynamic content scripts and CGI of Web sites--is the most important aspect that affects the performance of the site, If you manage a typical Apache server, you'll find that Apache's time spent in responding to an incoming connection and eventually sending the content to the customer is in milliseconds, while waiting for the required data resource often reaches a few seconds.

Of course, this is not to say that our optimization work is meaningless, the effect of optimization can not be belittled. In addition, it is important that by simplifying your setup files, you can significantly reduce the management burden on your servers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.