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.
For example, to determine the memory usage of httpd threads through PS, enter the following command:
# Ps-u APACHE-u Apache u
Userpid % CPU % memvszrss ttystat Start Time Command
Apache130670.05.3 149704 54504? Soct071: 53/usr/sbin/httpd-F/etc/httpd/CONF/httpd. conf-dapache2
...
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, which may be somewhat conservative, but it is very close to our goal.
In this article, we assume that each HTTPd process uses 27 MB of memory. Then, you need to determine the number of memories 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 theoretically, you can divide 102 concurrent processes into MB of memory for Apache to use (remember that unless your website requires a huge amount of traffic, otherwise, this situation is very rare ).
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 huge traffic will crash in an instant (even if you assume that each process occupies 5 MB of memory, you need GB of memory 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.
Other adjustable items include keepalive, keepalivetimeout, and maxkeepaliverequests. Recommended settings that can be placed in the httpd. conf file include:
Serverlimit 128 maxclients 128 keepalive onkeepalivetimeout 2 maxkeepaliverequests 100
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.
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 .)
$ AB-N 1000-C 100-K http://yoursite.com/index.php
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 ).
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.
Using AB is an excellent way to test and adjust Apache configurations. You should use it each time you make changes that affect performance.
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.
For example, to determine the memory usage of httpd threads through PS, enter the following command:
# Ps-u APACHE-u Apache u
Userpid % CPU % memvszrss ttystat Start Time Command
Apache130670.05.3 149704 54504? Soct071: 53/usr/sbin/httpd-F/etc/httpd/CONF/httpd. conf-dapache2
...
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, which may be somewhat conservative, but it is very close to our goal.
In this article, we assume that each HTTPd process uses 27 MB of memory. Then, you need to determine the number of memories 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 theoretically, you can divide 102 concurrent processes into MB of memory for Apache to use (remember that unless your website requires a huge amount of traffic, otherwise, this situation is very rare ).
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 huge traffic will crash in an instant (even if you assume that each process occupies 5 MB of memory, you need GB of memory 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.
Other adjustable items include keepalive, keepalivetimeout, and maxkeepaliverequests. Recommended settings that can be placed in the httpd. conf file include:
Serverlimit 128 maxclients 128 keepalive onkeepalivetimeout 2 maxkeepaliverequests 100
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.
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 .)
$ AB-N 1000-C 100-K http://yoursite.com/index.php
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 ).
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.
Using AB is an excellent way to test and adjust Apache configurations. You should use it each time you make changes that affect performance.