How to test and debug the Linux Apache server

Source: Internet
Author: User
Apache is the number one web server running on Linux. It can be used in many small places to adjust the performance of Apache and reduce its impact on system resources. One of them is to adjust the memory usage. Of course, it may take some time to achieve this goal. [Chinese webmaster site]

For example, to determine the memory usage of httpd threads through PS, enter the following command:

Chinaz.com

 

# Ps-u APACHE-u Apache u

Chinaz.com

 

Userpid % CPU % memvszrss ttystat Start Time Command [Chinese webmaster site]

Apache130670.05.3 149704 54504? Soct071: 53/usr/sbin/httpd-F/etc/httpd/CONF/httpd. conf-dapache2 chinaz.com

...

Chinaz.com

 

The above output shows that a single HTTPd process uses 50 MB of RSS (resident set size and small size) memory (or non-swap physical memory) and 149 MB of vsz (virtual) memory. Of course, this depends largely on the number of modules you load and run in Apache. This is by no means a fixed number. Because this number also contains a shared library package, it is not 100% accurate. We can think that half of the RSS number is the actual memory used by the httpd thread. This may be somewhat conservative, but it is very close to the target.

[Chinese webmaster site]

 

In this article, we assume that each HTTPd process uses 27 MB of memory. Then, determine the actual memory size that can be used by httpd. Depending on other processes running on the machine, you may want to require 50% of the physical memory to be used by Apache. In a system with 1 GB of memory, MB of memory can be divided into multiple 27mb of memory, that is, about 19 concurrent httpd memory. Some people insist that each httpd thread uses about 5 MB of memory, so in theory, 102 MB of memory can be divided into concurrent processes for Apache (remember, this situation is rare unless your website requires extremely large traffic ). Chinaz.com

By default, Apache allocates a maximum of 256 concurrent client connections or 256 processes (each of which corresponds to one request ). According to this setting, a website with a huge traffic will crash in an instant (even if each process occupies 5 MB of memory, GB of memory is required to meet the number of requests ). If no other action is taken, the system tries to use swap space through the hard disk to process tasks that cannot be completed in the physical memory. Chinaz.com

Other adjustable items include keepalive, keepalivetimeout, and maxkeepaliverequests. Recommended settings that can be placed in the httpd. conf file include:

[Chinese webmaster site]

 

Serverlimit 128 maxclients 128 keepalive onkeepalivetimeout 2 maxkeepaliverequests 100 chinaz.com

By reducing keepalivetimeout from 15 seconds to 2 seconds, you can add the maxclients command; 19 is too small, and 128 is much better. By reducing the number of seconds for a process to survive, you can allow more connections at the same time.

[Chinese webmaster site]

 

Of course, without the support of real tests, the numbers are meaningless. This is where AB works. Use AB to adjust the Apache configuration file (maxclients equals 256, serverlimit equals 256, and keepalivetimeout equals 15) so that it can meet 1000 requests (100 consecutive requests are generated concurrently) the adjustment method is as follows. (During the test, make sure that a terminal is opened on the server to observe the system load .) [Chinese webmaster site]

$ AB-N 1000-C 100-K http://yoursite.com/index.php chinaz.com

Now, change the above server settings to more conservative settings, restart Apache, and try to test again (always on a remote computer, instead of a local computer ).

[Chinese webmaster site]

 

In this test, different settings lead to a doubling of the execution time (27.8s and 16.8 s respectively), but the average load is 0.03 and 0.30. This may slow your website down, but it will make sure it will not crash under high load. Remember that you will need to perform multiple tests to get an average value.

[Chinese webmaster site]

 

Using AB is an excellent way to test and adjust Apache configurations. You should use it each time you make changes that affect performance.

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.