Apache is the number one Web server running on a Linux operating system. Many small places can be used to adjust the performance of Apache and reduce its impact on system resources. One is to adjust the memory usage, of course, it may take some effort to achieve this goal.
For example, by using PS to determine the memory usage of a httpd thread, you can 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 a single httpd process using MB of RSS (resident set size) memory (or non-switched physical memory), and 149 MB of vsz (virtual) memory. This, of course, depends largely on the number of modules you download and run in Apache. This is by no means a fixed number. Since this number also contains a shared library package, it is not 100% accurate. We can think that half of the RSS number is the amount of memory that the httpd thread actually uses, which may be a bit conservative, but it's very close to our goal.
In this article, we assume that each httpd process is using MB of memory. Then, you need to determine the number of memory that can be httpd to actually use. Depending on the other processes running on the machine, you might want to require 50% of the physical memory to be used by Apache. On a system equipped with 1GB of memory, 512MB of memory can be divided into 27MB of memory, which is approximately 19 concurrent httpd memory. Some people insist that each httpd thread "really" uses about 5MB of RAM, so theoretically you can divide 512MB memory into 102 concurrent processes for Apache use (remember that this is very rare unless your site requires extremely large traffic).
By default, Apache allocates up to 256 concurrent client connections, or 256 processes (each of which corresponds to one request). With this setting, a Web site with a huge flow of traffic crashes (even if you assume that each process consumes 5MB of memory, it needs 1.3GB of memory to satisfy the number of requests). If no other action is taken, the system attempts to use swap space through the hard disk to handle tasks that it cannot complete in physical memory.
Other items that can be adjusted include settings such as KeepAlive, KeepAliveTimeout, and maxkeepaliverequests. The recommended settings that can be placed in the httpd.conf file are:Serverlimit 128MaxClients 128KeepAlive onkeepalivetimeout 2MaxKeepAliveRequests 100
By reducing the keepalivetimeout from 15 seconds to 2 seconds, you can increase the maxclients command, 19 is too small, and 128 is much better. By reducing the number of seconds that a process survives, you can allow more connections at the same time.
Of course, if there is no real test behind the back, the numbers are meaningless, and that's where AB works. Use AB to adjust the Apache configuration file (MaxClients equals 256, Serverlimit equals 256, KeepAliveTimeout equals 15) to meet the adjustment methods for 1000 requests (100 consecutive requests concurrent) as follows. (Make sure that a terminal on the server is open to observe the system's load while performing the test.) ）$ 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 from the remote computer, not the native).
In this test, the different settings result in a one-fold gap (27.8s and 16.8s, respectively) for execution, but the average load is 0.03 and 0.30. This may make your site a little slower, but make sure it doesn't crash under high load. Also keep in mind that you will need to do multiple tests to get an average.
Using AB is an excellent way to test your Apache configuration, and you should use it every time you make changes that affect performance.