Reprinted from: http://blog.csdn.net/ldl22847/article/details/7753865
For IIS administrators, it is often encountered that the CPU of the web server occupies 100% . The following is a summary of personal daily work and some solutions, mainly used to analyze some reasons why w3wp.exe (IIS) occupies 100% of the CPU and solution, hope it will help you
Explanation of w3wp.exe : full name, IIS Application Pool Process. w3wp.exe is part of the IIS tools . w3wp.exe is a process associated with the application pool in IIS ( Internet Information Server ) . If you have multiple application pools, there will be corresponding multiple w3wp.exe process instances running. This process is used to allocate a large number of system resources.
Common reasons for w3wp.exe (IIS) CPU usage 100% are as follows:
1. Due to the large amount of Web traffic and the high pressure on the server
This is also the most common situation. If there is a large number of Web visits, especially if there are too many people online at the same time, and the Requests Current ( current number of requests) processed is too high, it will cause greater pressure on IIS and the server at the same time. In particular, the server needs to continuously calculate and send the generated pages to the client. These all require a lot of CPU resources, resulting in 100% CPU
2. The complexity of the program logic of the dynamic page (.aspx)
This problem is also quite serious for the CPU usage of w3wp.exe . It may not have much impact when the access level is relatively small, but for high-concurrency websites, especially the Requests Current of Asp.Net When it exceeds 250 , it will be an important factor for w3wp.exe to occupy the CPU .
I have encountered such a situation, two webs (A and B) are deployed in two servers with similar configurations, and the traffic of both sites is very large, and the access pages are concentrated in two separate sites of the two sites. page, and the number of IIS connections for these two pages is about 50 , but the complexity of the page program is much wrong . The pages in site A have only a few simple Repeater bindings, while the pages in site B , There are tons of bindings, string filter replacements, Repeater nested bindings, and so on. In such a situation, in a high-traffic and high-concurrency environment, when the number of IIS connections for site A reaches more than 3 W , the CPU usage is still about 50% , while for site B when the number of IIS connections reaches about 7K , the CPU More than 90% , causing a lot of pressure on the server, and IIS was blocked.
3. There is an infinite loop in the page program
If the amount of Web traffic is not large, but the CPU usage is very high, then the program in the page must have an infinite loop or a program statement with serious performance.
4. Http download site
If the site is an HTTP download site, I have also encountered the situation that w3wp.exe occupies 100% of the CPU
5. Server resources are not automatically released
Sometimes, the traffic of a site increases sharply within an hour, and as a result, the operating system allocates more CPU resources, but when the traffic goes down, the CPU occupied by w3wp.exe is not released in time, and remains above 90%
6. Operations on IIS log files
For example, analyzing the data in the IIS log file at this time, importing the IIS Log log into the database, etc., will also cause this phenomenon
Solution :
1. Quickly locate the problem site
Use the iisapp -a command to quickly locate the problem site. Of course, if the current server only runs one web site, then this step can be skipped
Enter iisapp - a in cmd , and the information in the following figure will appear:
Of course, this requires that you do not have a site, and you must have an independent application pool corresponding to it. The name of the application pool is preferably the name of the site, as shown below:
关于 IIS 的应用程序池的配置,这里就不说了,不懂的可以search 下
之后,再打开任务管理器,如下图:
观察进程为 w3wp.exe 的,查看那个CPU 占用的高,再利用其 PID 于 iisapp 中列出的结果对比,就能轻松的找出是那个站点占用的CPU过高了
2. 重启 IIS 和 应用程序池
此步是紧急处理,一般都是治标不治本的步骤。如果你的站点搭建的有 负载均衡(负载均衡、NLB),那么请在 负载均衡(负载均衡、NLB)把当前服务器下了,然后重启。如果你没有 负载均衡(负载均衡、NLB),而且你的站点又是在线的,那么,就悲剧10多秒吧,短暂的不能访问吧
3. 给页面加上页面级别缓存
如果Web 是 Asp.Net 程序,那么请一定要 <%@ OutputCache Duration="10" VaryByParam="none"%>。但是有好多人都没有用好OutputCache ,导致经常出现下载页面的问题,所以都放弃了使用,这里有 OutputCache 导致页面下载的解决办法 。
OutputCache 非常有用,好处有三:直接从内存读页面,页面响应速度更快,用户体验更好;大大的降低了服务器的压力,特别是对于高并发的网站,特别是 CPU 的压力;减少了 DB 的强求,降低 DB(数据库)的压力。
4. 检查页面逻辑
如果WEB 流量很低,但是还有 w3wp.exe(IIS ) CPU 占用 100% 左右的情况,那么就检查页面的代码逻辑吧,很有可能是死循环或大量的运算导致。