IIS6.0 application pool recycling and working process

  
                       After a long-running website program of the company, the speed is slower. After restarting the website, the speed is obviously faster. It is estimated that the memory and CPU resources occupied by the website program cannot be released in time, and it is necessary to restart the website to release resources at intervals. But manual restart is not always a solution to the problem. How can we achieve automatic management? The application pool auto-recycling feature of IIS 6.0 can solve this problem.

An application pool is a configuration that links one or more applications to one or more worker process collections. Because applications in an application pool are separated from other applications by worker process boundaries, applications in one application pool are not affected by problems that occur in applications in other application pools.

To configure an application pool for a web application, you need the following steps: 1) Create an application pool, right click on "application pool", "new/application pool", name it KefuAppPool; 2) as a web application Specify the application pool, select KefuAppPool in the "Application Pool (N)" in the website virtual directory property "Application Settings"; 3) Set the application pool automatic collection method. There are several ways to recycle: http://www.45it.com
a. According to the running time
The system default is 1740 minutes, which is 29 hours, this is not very good control, it is recommended not to use.

b. Number of requests
This depends on the specific situation. If there are only 10 requests, but 5 are requesting the page that compares the resources (probably a statistical annual report), then the process will be dropped. If there are 1000 requests, one does not run. Comparing the pages that occupy the resources, the process is definitely normal at this time, so the decision based on the number of requests does not necessarily meet the actual needs.

c. Planned time
This is actually very good, but what time is it good to recycle? Usually we are set at two or three o'clock in the morning, this time is necessary for recycling, but it is not very suitable for the appearance of high memory usage.

d. Memory (virtual memory or used memory)
This is really appropriate for the process caused by memory problems, but setting a large value is a very important issue. The value should not be too small, otherwise it will be automatically reclaimed if the number of visits is much larger than this value. This is not necessary. Be sure to observe the actual occupancy of the process and make a decision.
The following focuses on the understanding of the work process recycling application pool.
By default, the WWW service establishes "overlap reclaim", that is, continues to run the worker process to be terminated until after the new worker process is started. In an overlapping reclamation scenario, the process to be recycled continues to process the request while the WWW service creates an alternate worker process. Start a new worker process before stopping the old worker process, and then direct the request to the new process. This design prevents service interruptions because the old process remains in communication with HTTP.sys to process requests before it is shut down. Because the close timeout value that can be overlapped or started is configurable, the process can be terminated while the worker process is still processing the request (if it has not processed the request within the time limit).
Note: When a WWW service recycles a worker process, it does not disconnect the existing TCP/IP connection. The HTTP protocol stack (HTTP.sys) establishes and maintains a TCP/IP connection.

IIS application pool for each managed by a "work process" that is "W3wp.exe" process. If there are multiple applications running in the application pool, we can see multiple w3wp.exe. This can be seen in the Task Manager. As shown in the following figure, there are two w3wp.exe processes in the Task Manager, which correspond to two application pools where the application is running.


run iisapp -a at the command prompt, you can view which w3wp.exe and associated application pool. 1) Add the display pid field in the task manager; 2) Run iisapp -a at the command prompt. Note that the first time you run, you will be prompted for no js support, click OK. Then run it again. This will show the application pool corresponding to the pid. As shown on the left side of the figure above, the application pool KefuAppPool is associated with w3wp.exe with PID=3232, and the application pool ReportServer is associated with w3wp.exe with PID=3572.

The following figure shows the manual execution of the application. The recovery of the program pool KefuAppPool, before the recycling, the recycling of the application pool and the work process after the recovery. We noticed that a work process (PID=3896) was added during the recovery process. After the work process (PID=3896) was started, the old work process (PID=5716) was stopped, and the new work process (PID=3896). ) Officially replace the old process work, which is very good to prevent the service from being interrupted during the application pool recycling process, ensuring the continuous operation of the program. The work process PIDs of the other two application pools are useless. This figure is a good illustration of the process of application pool recycling.

IIS application pool automatic recycling mechanism brings us convenience, but also causes potential problems. We must pay special attention when writing functions that depend on global events in the Global file, especially the functions that are executed regularly every day. After restarting the IIS application pool, if there is no user accessing the website, the Application_Start event cannot be activated, and the function cannot be used. Executed.

Copyright © Windows knowledge All Rights Reserved