Performance optimization method of Apache in Wins2003 system

  • 2020-05-07 20:41:17
  • OfStack

In order to meet the high load requirements of the website, when adjusting the Apache parameters, it was found that the process often took up too much memory and crashed. After constant optimization and modification of the combination of parameters, finally let the server stable, can meet a large number of access to the test and application requirements. The author summarized the problems and solutions in the debugging process as follows for the reference of network administrators with similar requirements (system environment is Windows Server 2003 and apache2.2.8) :

1, http-mpm.conf Settings

The thread count control file for
Apache is http-mpm.conf, under the conf/exrtra directory. To make this configuration file work, you need to # remove Include conf/extra/ httpd-mpm.conf in httpd.conf for http-mpm.conf to take effect.

In the Windows system, what works is the Winnt mpm segment,

 
<IfModule mpm_winnt_module> 
ThreadsPerChild 150 
MaxRequestsPerChild 0 
</IfModule> 


The above is the default configuration, 1 general enough, but the heavy load of the site needs to be modified, otherwise access to the site will be slow or no response. In the actual setting, the real-time connection status of apache can be checked according to apache-status, and the number of threads occupied in apache can be adjusted accordingly. The final setting of my server is as follows:

 
<IfModule mpm_winnt_module> 
ThreadsPerChild 350 
ThreadLimit 350 
MaxRequestsPerChild 10000 
</IfModule> 


Where ThreadLimit is the limit of the number of threads that occupy the system. After modification, the effect will be directly seen in apache-status, which is the corresponding maximum number of available threads (as shown in the figure).

MaxRequestsPerChild is the maximum number of requests for a process, which is the number of caches the site receives requests from. Setting too small can affect server performance because it takes up too much cpu time, and too large can take up memory resources. The number of large site files is thousands of, so the administrator should be set according to the site, as long as not zero (unlimited) can be, in order to prevent memory overflow.

ThreadsPerChlid is the number of child threads of the Apache process, meaning that the server has opened so many threads waiting to respond to a client request. This parameter needs to be adjusted according to the real-time monitoring situation of apache-status. Too much will cause the memory to grow too fast until the server goes down. Too little will cause the server connection queue to fill up at the peak time, resulting in slow connection to the website. Meanwhile, we should modify the timeout setting in another configuration file httpd-default.php to match this parameter.

2, httpd-default.conf Settings

Remove the # before Include conf/extra/ httpd-default.conf from httpd.conf for httpd-default.php to take effect. We need to adjust the following parameters:

Timeout 15

This parameter is a connection timeout, and the default of 300 seconds is obviously too large. Reducing this parameter will reduce the number of simultaneous connections, that is, the number of threads actually occupied by the user, so as to match the ThreadsPerChlid parameter above.

KeepAlive On

This parameter is whether to keep the connection alive. At present, a page 1 in the website usually contains multiple files, so there will be multiple requests when corresponding users visit it. Therefore, opening can improve the performance of the server.

MaxKeepAliveRequests 50

This parameter is the maximum number of live connection requests and can be adjusted according to the number of files the page actually contains.

KeepAliveTimeout 5

This parameter is the timeout time of the live connection, as long as it is set to less than Timeout.

After this setting, Apache achieves a relatively balanced effect in responding to requests and preventing malicious attacks. Of course, due to the different memory recovery mechanism and process management, Apache is still not as stable as Unix in the long-term operation of Windows, so we can let Apache automatically restart once every morning when the number of visitors is low, so as to recover resources. This can be easily accomplished with the planned tasks built into Windows. In this way, we are able to make Apache as stable as Unix1 over a long period of time on the Windows platform.

windows apache and mysql timing automatic restart & server timing automatic restart

Sometimes feel that the server run time is too long, resulting in server memory and other pressure. Therefore, it is very beneficial to complete the memory release of apache and mysql without restarting the server (setting the restart time to the lowest traffic).
First, the reboot of apache.

There are two methods of automatic and timed restart of apache (two, the second one can start apache and mysql simultaneously, so the second one is recommended) :

type 1, using a task plan
began > > The program > > The attachment > > Management tool > > Task plan
Add task plan > > Next step 1 > > apache restart > > Select the time (can be set to 2-4am every day) > > One way is ok.

The second type of (which I think is simpler, but is also a task plan) USES the at command to add the planned task

1. Create a new apacheautostart.bat file in c: root directory, then right click to edit, set the file content as follows and save:

 
@ECHO OFF 
net stop apache2 
net start apache2 
net stop mysql 
net start mysql 

(note: apache2 and mysql above are service names.)

2. "start "-" run "cmd"- "execute "at 04:00 c:apacheautostart.bat"
This automatically restarts apache and mysql at 4am each day
(note: 04:00 is the restart time, c:autostartserver.bat is the bat file address of step 1)

The reboot of mysql is also restarted with the at command method above, so the second method is recommended.


Also, you can add an auto-restart feature to your server on a regular basis (such as restarting the server once a week).

It can be implemented with the at command and shutdown command.

AT command can arrange commands and programs to run on a specific date and time, shutdown can shut down and restart your computer, under the command line to a specific time in every Sunday automatically restart the computer, only need to input in the command prompt "at 2:00 / every: week 1 shutdown/l/r/y/c", this will be a week 1 at 2 a.m. automatically restart the computer.


Related articles: