Let's take a look at the load map.
For half a day. Some optimizations are made:
The number of visits is not that high when the optimization is complete. So I don't know what the effect is. Let's see how it works.
[Root@localhost ~]# Netstat-an | grep established | Wc-l
210 Connected Number
[Root@localhost ~]# PS aux|grep httpd|wc-l
55 Number of processes
[Root@localhost ~]# Ps-ef|grep httpd|wc-l
The number of Apache can handle
[Root@localhost ~]# netstat-nat|grep-i "80″|wc-l
698 Number of Network requests
Real-time detection of httpd connections:
Watch-n 1-d "Pgrep httpd|wc-l"
Modify the./apache/conf/httpd.conf file first.
# VI httpd.conf
Remove the # before the "#Include conf/extra/httpd-mpm.conf".
Save.
Second: Modify the./apache/conf/extra/httpd-mpm.conf file again.
# VI Httpd-mpm.conf
Find the <ifmodule mpm_prefork_module> line.
Original:
<ifmodule mpm_prefork_module>
Startservers 5
Minspareservers 5
Maxspareservers 10
MaxClients 150
Maxrequestsperchild 0
</IfModule>
After modification
<ifmodule mpm_prefork_module>
Startservers 10
Minspareservers 10
Maxspareservers 15
Serverlimit 2000
MaxClients 1500
Maxrequestsperchild 10000
</IfModule>
When Apache is started, Apache automatically creates startservers processes and tries to keep the number of idle processes between Minspareservers and maxspareservers.
If the idle process is less than minspareservers,apache, it will create a new process at a rate of approximately 1 per second.
If the idle process is less than maxspareservers,apache, the extra idle process is removed and the server resources are freed.
The maximum number of processes is controlled by maxclients and can only be set to 256 in Apache1.3, but in Apache2.0, you can break the 256 limit by adding a Serverlimit project at the beginning of the configuration, which must be maxclients≤ serverlimit≤20000
Maxrequestsperchild is used to control how many requests are automatically destroyed by each process after processing, and this parameter can be set to 0 for infinity (that is, not destroying the process).
Apache high load performance tuning
First read the Apache configuration optimization Recommendations, and then adjust the relevant parameters to observe the server status.
Apache Configuration Optimization Recommendations:
Enter the/usr/local/apache2/conf/extra directory
Apache optimization,
After the above operation, Apache has been able to run normally. However, for a slightly larger number of sites, Apache these default configuration is not enough to meet the needs, we still need to adjust some of the Apache parameters, so that Apache can be in a large traffic environment to play a better performance. Here's a description of the parameters that have a significant performance impact in the Apache configuration file httpd.conf.
(1) Timeout This parameter specifies the maximum wait time (in seconds) before Apache receives a request or sends the requested content, and if more than that time Apache discards processing the request and releases the connection. The default value for this parameter is 120, the recommended setting is 60, and the Web site with a large number of visits can be set to 30 or 15.
(2) KeepAlive This parameter to control whether Apache allows multiple requests in one connection and opens by default. However, for most forum type sites, it is usually set to off to turn off this support.
(3) Mpm-prefork.c by default, Apache uses the prefork (process) working mode, which can be said that this part of the parameter setting is the core and key to the impact of Apache performance. The following configuration segments can be found in the configuration document by the user:
Startservers 5
Minspareservers 5
Maxspareservers 10
MaxClients 15
Maxrequestsperchild 0
This is the configuration to control the work of the Apache process, in order to better understand the parameters of the above configuration, let us first understand how Apache control process work. We know that in a UNIX system, many service (Daemon) daemons Create a process at startup to prepare for a possible connection request, and the service enters the port listening state when a request from the client is sent to the port on which the service is listening. The service process processes the request, which is exclusive during processing, that is, if there are other requests arriving at this time, the requests can only be "queued" for the current request processing to complete and the service process is freed. This can result in more and more requests waiting in the queue state, which is actually a very low service handling capability. Apache solves this problem by using the Prefork mode. Let's look at how efficiently Apache actually works.
When Apache starts, Apache initiates a startspareservers idle process while preparing to receive processing requests, and when multiple requests arrive, Starspareservers is less likely to occur. When the idle process is reduced to minspareservers, Apache will restart the startsservers process standby in order to continue to have sufficient process processing requests, thus greatly reducing the likelihood of request queue waiting, resulting in improved service efficiency, That's why it's called pre-fork. Let's keep track of Apache's work and assume that Apache has started 200 processes to handle requests, theoretically, when Apache has 205 processes, and over time, Assuming that there are 100 requests that have been responded and processed by Apache, then the 100 processes will be freed up as idle processes, then Apache has 105 idle processes at this time. For services, starting too many idle processes does not make any sense, but will reduce the overall performance of the server, then Apache really have 105 idle process? Of course not! In fact, Apache checks itself at any time, and when it finds that there are more than maxspareservers idle processes, it automatically stops shutting down some processes to ensure that there are too many idle processes. Here, the user should have a certain understanding of how Apache works, and if you want more detailed instructions please refer to the Apache manual documentation.
We still have two parameters that are not covered: maxclients and Maxrequestperchild;maxclients Specify how many clients the Apache will allow to connect with at the same time, if more than maxclients connections, The client will get a "server Busy" error page. We see that by default maxclients is set to 15, which is obviously not enough for some midsize sites and large sites! Maybe you need to allow 512 client connections at the same time to meet your application requirements, so let's change the maxclients to 512, Save httpd.conf and exit, restart Apache, unfortunately, during the restart process you saw some error prompts, the Apache reboot failed. The error prompt tells you maxclients maximum can only be set to 256, I believe you must be very disappointed. But don't be discouraged, Apache as a world-class Web server must not be so thin! By default, maxclients can only be set to no more than 256 integers, but if you need to be fully customizable, at this time you need to use the Serverlimit parameters to use, simply say serverlimit is like a bucket, And maxclients is like water, you can hold more water by replacing the larger bucket (setting the serverlimit to a larger value) (maxclients), but note that The set value of maxclients can not be larger than the set value of Serverlimit!
Note: maxclents < Serverlimit
Let's take a look at the Maxrequestperchild parameter, which specifies how many threads can work at the same time in a connection process. Perhaps this explanation is too professional, then you just think of "network ants", "Internet Express FlashGet" in the "multiple points at the same time download" can be, this parameter is actually a limit can use a few "points." The default setting is 0, which is: No limit. However, it is important to note that if you set this value too small to cause access problems, if there is no special need or the amount of traffic pressure is not very large to maintain the default value, if the number of visits is very large, the recommended setting is 2048.
Well, that explains so much, let's look at the recommended configuration for the modified PERFORK.C configuration section:
Startservers 5
Minspareservers 5
Maxspareservers 10
Serverlimit 1024
MaxClients 768
Maxrequestsperchild 0
Having completed the above Apache adjustment, Apache has achieved a greater performance improvement.