The optimization method of Apache performance in Wins2003 system _win server

Source: Internet
Author: User
Tags server memory

In order to meet the requirements of the site's high load, when the Apache parameters are adjusted to find that the process often consumes too much memory caused by the machine. After continuous optimization and modification of parameter combination, finally let the server stabilized, can meet the test of a large number of visits and application requirements. The author sums up the problems and solutions in the debugging process as follows, for the network administrator with similar requirements (the system environment is Windows Server 2003 and apache2.2.8):

1, http-mpm.conf settings

Apache's thread number control file is http-mpm.conf, under the Conf/exrtra directory, to make this profile work, you need to remove the Include conf/extra/httpd-mpm.conf before # in httpd.conf To make http-mpm.conf effective.

In the Windows system, the Winnt MPM segment is working,

Copy Code code as follows:

<ifmodule mpm_winnt_module>
Threadsperchild 150
Maxrequestsperchild 0
</IfModule>


The above is the default configuration, generally enough, but the load of the site will need to be modified, otherwise visit the site will slow or no response. The actual settings can be based on the Apache-status view of the Apache real-time connection status, see the number of threads in which to adjust the appropriate, my server is finally set as follows:

Copy Code code as follows:

<ifmodule mpm_winnt_module>
Threadsperchild 350
Threadlimit 350
Maxrequestsperchild 10000
</IfModule>


Where Threadlimit is the limit of the number of system threads, modified to see the effect directly in Apache-status, is the corresponding maximum number of available threads (as shown in the figure).

Maxrequestsperchild is the maximum number of requests for a process, both the number of cached requests that the Web site receives. Setting too small can affect server performance because it takes up more CPU time and is too large to consume memory resources. The average number of large web site files are thousands, so the administrator should be based on the site's own settings, as long as not 0 (unrestricted) to prevent memory overflow.

Threadsperchlid is the number of child threads in the Apache process, meaning that the server is running up so many threads to wait for a response to a client request. This parameter needs to adjust according to the Apache-status real-time monitoring condition, too the assembly causes the memory to grow too fast, until the server is machine, too small can cause the server connection queue to fill at peak time, thus causes the website connection to be slow. At the same time we should modify the timeout setting in another profile httpd-default.php to match this parameter.

2, httpd-default.conf settings

Remove the # before the include conf/extra/httpd-default.conf in the httpd.conf to make the httpd-default.php effective. We need to adjust the following parameters:

Timeout 15

This parameter is a connection timeout, the default of 300 seconds is obviously too large, the reduction of this parameter will reduce the number of simultaneous connections, that is, the number of threads the user actually occupies, so you can play with the above threadsperchlid parameters.

KeepAlive on

This parameter is to maintain a live connection, the current site of a page typically contains multiple files, so the corresponding user access will have multiple requests, so open can improve server performance.

Maxkeepaliverequests 50

This parameter is the maximum number of live connection requests, which can be adjusted according to the number of files actually contained in the Web page.

KeepAliveTimeout 5

This parameter is the timeout time for live connections, generally as long as the set is less than timeout.

With this setting, Apache has a more balanced effect in responding to requests and preventing malicious attacks, of course, because the memory recovery mechanism and process management are different, the long-term running of Apache in Windows is not as stable as UNIX, So we can allow Apache to automatically reboot once a few hours a day to reclaim resources. A scheduled task with Windows Self can be implemented simply. In this way, we make Apache provide services as long and stable as UNIX under the Windows platform.

windows Apache and MySQL timed automatic restart & Server timed automatic restart

Sometimes feel that the server running too long, causing the server memory and so on too much pressure. Therefore, it is very useful to complete the memory release of Apache and MySQL without restarting the server (set the restart time to the lowest number of visits).
First, the Apache reboot.

There are two methods of automatic timing restart of Apache (two, the second one can start Apache and MySQL at the same time, so recommend the second kind):

The first, the use of task planning
Start >> Procedures >> Attachments >> management Tools >> Mission plan
Add Task Schedule >> next >>apache restart>> selection time (can be set to 2-4 dots per day) >> all the way to determine.

the second (personally feel simpler and also a task plan) is to add a scheduled task with the AT command

1, in the C: the directory to create a new Apacheautostart.bat file, and then right-click Edit, the contents of the file set to save as follows:

Copy Code code as follows:

@ECHO off
net stop Apache2
net start apache2
net stop MySQL
net start MySQL

(Additional note: The above apache2 and MySQL for the service name.) )

2, "Start"-"Run" cmd "-" Execute Command "at 04:00 C:apacheautostart.bat"
That way, the system automatically restarts Apache and MySQL 4 o'clock in the morning every day.
(Additional note: 04:00 restart time, c:autostartserver.bat as the first step of the bat file address)

The MySQL reboot is also restarted by the AT command method above, so the second method is recommended.


Also, you can add a timed automatic reboot to your server (such as restarting the server once a week).

Can be implemented with the AT command and the shutdown command.

The AT command can schedule commands and programs to run at a specific date and time, shutdown can shut down and restart the computer at the command line, automatically restart the computer at a specific time every Sunday, and simply type at the command prompt at 02:00/every: Monday shutdown/l/r/y /C ", which will automatically restart the computer at 2 o'clock in the morning every Monday.

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.