How to set the recycling time of the IIS program pool to minimize the impact on users?

As a .Net developer, I actually know very little about the application pool of IIS. In my work, I have encountered the situation that the website could not be opened for no reason. After searching for a long time, I could not find the reason. After I found a program pool for the website, I found that I could access it normally. This also made me curious and doubtful about identifying the problem, so I started to look for some information on this. It turns out that the application pool of IIS generally automatically defaults. Recycled, by default, it is recycled every 29 hours, so many times we have not encountered it because it is not working time. So for Internet web applications, how to recycle the program pool without the user's perception? (minimum impact on users )

Simple understanding of IIS application pool

An application pool can be thought of as a container for the memory allocated by a computer to a web application.

Someone on the Internet likened this: If memory is water, then the application pool is the fish tank, and the web application is the goldfish in the fish tank. Multiple web applications can be placed in the same application pool, which means that a fish tank can hold multiple goldfish. If there are too many goldfish and the space of the fish tank is limited, then the goldfish will compete for living space, and the fish tank that is not very strong will break, and all goldfish (websites) will be affected, that is, the memory will be insufficient, resulting in memory overflow. question. Over time, the water quality in the fish tank will deteriorate, and the goldfish seems to live in a stinky ditch, so we need to change the water regularly (recycling process pool). 

 

Program pool automatic recycling optimization

The default recycling interval of the program pool of IIS is 1740 minutes (29 hours). During the automatic recycling process, the application pool will be emptied, and the data retained in the memory will be cleaned up (equivalent to IIS restart). For Internet applications, in order to reduce the burden on the database server, a large amount of data may be temporarily stored in the memory. Recycling will cause the loss of memory data. If it is not saved to the database in time, it may cause problems in the application. If you encounter a peak system usage period, recycling may cause the application to become unresponsive for a period of time (a suspended state), giving users a very bad experience. Before optimizing the application pool, we should first understand several configuration information of the application pool:



Disallow recycling on configuration changes: If True, the application pool will not be recycled when configuration changes occur. 
Fixed interval (minutes): After the set time is exceeded, the application pool will be recycled. If it is 0, it means that the application pool will not be recycled at a fixed interval. The system default time is 1740 minutes (29 hours). 
Disable Overlapped Recycling:  If true, application pool recycling will occur so that an existing worker process exits before another worker process is created. 
Request Limit:  The maximum number of requests that the application pool can process before being recycled. A value of 0 means there is no limit to the number of requests the application pool can handle. 
Generate recycling event log entry: An event log entry is generated each time a specified recycling event occurs, and the detailed settings in it are not introduced one by one. 

Problem analysis: Is it reasonable to recycle every 1740 minutes (29 hours)?

Not very reasonable. During this period, it is possible that the application is at the peak of access. Because the recycling time is different every day, it is very likely to be recycled during the peak period, which will cause problems in website access in a short period of time. Therefore, to avoid minimizing the impact on users, we need to fully analyze the access situation of the application, such as which time period is the peak and which time period has the least number of visitors. After knowing this, the application deployer should set a fixed recycling time. For example, a website has the least number of visitors at 2:00 in the morning, then it can set the "specific recycling time" at 2:00 in the morning, and the specific recycling time in the application pool Time is supported to set multiple, please note. 

 

 

1. Choose to recycle at 2 am every day

 

 

 

 

2. Recycling every Saturday night

We recommend using the Windows "Task Scheduler" to configure an operating system timed task execution script to realize IIS recycling, which is easy to set and can be adjusted flexibly. To execute the functions of IIS through scripts, you need to check the "IIS management scripts and tools" in the management tools during the IIS installation and configuration (see the figure below).

Using vbs scripts and batch files, combined with the task scheduler, ensure that IIS recycling is performed at 1 o'clock in the middle of the night every Saturday.

Recyclepool.vbs  file content:

appPoolName = WScript.Arguments(0)

Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

Set oAppPool = oWebAdmin.Get("ApplicationPool.Name='" + appPoolName + "'")

oAppPool.Recycle

set fso=createobject("scripting.filesystemobject")

if (fso.fileexists("d:\appPool\recycleIISPool.log")) then

   '1-forreading,2-forwriting,8-appending

   set file=fso.opentextfile("d:\appPool\recycleIISPool.log",8,ture)

else

   set file=fso.createtextfile( "d:\appPool\recycleIISPool.log",8,ture)

end if

'write(x) writes x characters, writeline writes newlines, writeblanklines(n) writes N blank lines

file.writeline now&" The application pool ""&appPoolName &"" has been recycled successfully."

file.close

Recyclepool.bat file content:

cscript D:\appPool\recyclepool.vbs platweb

 

Using vbs scripts and batch files, combined with the task scheduler, ensure that IIS recycling is performed at 1 o'clock in the middle of the night every Saturday.

Successfully used windows scheduled task to solve the problem of IIS timing recycling.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325309944&siteId=291194637