About Apache Optimization

Source: Internet
Author: User
Any Reprinted However, the original author charlee and original link http://tech.idv2.com/2007/08/09/about-apache-perf-tuning/must be identified in a timely manner.

TodayApache. Why optimization? Because the server resources are insufficient. There are many aspects of resources, but according to the barrel theory, as long as one resource is insufficient, the performance of the entire server will be affected (so-called bottleneck ).

Server resources

What are the server resources? For websitesCPU,TCP connectionsBoth. The CPU is represented in the number of tasksLinuxUseAverage Load(Loadavg. You can run the following command (refer to this Article ):

 
CAT/proc/loadavg

For a single-CPU server, loadavg is higher than 1, indicating that the task queue is waiting, and the CPU is too busy. If it exceeds 2, the performance will be significantly reduced.

To view the number of TCP connections, run the following command:

 
Netstat-ant | grep: 80 | WC-l

To monitor server resources in real time, refer to the opennms project.

Note 1: memory is not counted. Low prices make it rare for website servers to go down due to insufficient memory.
NOTE 2: CPU % is an instantaneous CPU usage, which usually does not reflect the overall load.

Apache configuration command

Apache provides the following resource configuration commands.

Keepalive Whether persistent connection is allowed
Maxkeepaliverequests Maximum number of allowed persistent connections
Keepalivetimeout How many seconds after no request is sent for a persistent connection?
Startservers How many server processes are started at Initial Startup?
Minspareservers Minimum number of idle Server Processes
Maxspareservers Maximum number of idle Server Processes
Maxrequestsperchild Maximum number of requests processed by each sub-process

Keepalive

The first three keepalive commands are used to set persistent connections. Generally, each HTTP request corresponds to a TCP connection,ImageIn the web page, the client sends multiple HTTP requests in an instant. At this time, setting up multiple TCP connections greatly reduces the response speed. At this time, through continuous connection, users can send multiple HTTP requests in a TCP connection, reducing the number of established TCP connections and improving the response speed.

In this case, the access_log should be used to calculate the number of consecutive HTTP requests, the interval, and the number of visits to determine the value of maxkeepaliverequests and keepalivetimeout. Keepalivetimeout is too small to play the role of continuous connections; it is too large, continuous connection is delayed, a waste of TCP connections not to mention, and worse, the number of httpd processes in the system will continue to increase, this increases the system load and even causes the server to lose response.

However, when processing dynamic web page requests, since users rarely instantly request multiple dynamic web pages (usually after opening the page and reading the next page for a long time), enabling keepalive is a waste of TCP connections.

The conclusion is that keepalive off is enabled for dynamic web pages to increase throughput, and static content slices and JSCodeKeepalive on to reduce the number of TCP connections.

But one Apache can only have one keepalive setting. What should I do? It's easy to get two servers, one with a script and one with a picture.

Server process count

Let's talk about startservers, minspareservers, and maxspareservers. Startservers does not need to be modified because Apache automatically adjusts the number of sub-processes. Minspareservers and maxspareservers are the number of idle sub-processes. What is the number of idle sub-processes? Assume that there are 30 httpd processes in the system at a specific time, one of which is the parent process and 20 are processing requests. Then the number of idle sub-processes is 9.

There are fewer idle processes, and a large number of sudden requests will make the server tired of Process Creation and reduce efficiency. However, too many will increase the number of system processes and increase the system load.

In fact, the default value is enough to handle general bursts of requests, so do not modify these settings unless the traffic is particularly huge for websites.

Even if the traffic is extremely high, the Server Load balancer system is used to reduce the access volume of each server. These values are not modified.

Maxrequestsperchild

This value sets the number of requests processed by the sub-process to automatically end. This option is used to prevent the process from using too much memory due to memory leakage. Generally, the default value is enough.

Summary

In other words, the most important thing is the keepalive settings, and the performance adjustment is to adjust the values of keepalive and keepalivetimeout.

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.