We host a lot of sites at BizStream, with a lot of custom code behind them. Every once in a while, one of those sites has a bug that spikes the server CPU at 100% for a while, taking down all the other sites on the server. This post aims to temporarily fix the spiked CPU so it doesn’t negatively affect all the other sites on the server while you’re working furiously to figure out what is causing the spikes in the first place and fix the real problem.
The temporary “fix” that we implemented was to have IIS kill the w3wp process if it surpasses 85% for more than 5 minutes.
This can be done via the IIS user interface in the following manner:
- Open IIS
- Expand the server and click Application Pools
- Select the application pool you’re working with
- Click Advanced Settings
- Under the CPU section, set Limit to the threshold you wish to be the maximum
- IIS 8.5 – 85 means 85%
- IIS 7, 7.5, 8 – 85000 means 85%
- Set Limit Action to “KillW3wp”
- Click OK to apply.
Things to Remember
This makes sense in our case because, with the sites, we’re hosting, from time to time, they might spike the CPU for a couple of seconds, so we didn’t want to kill the process every time. If your site CPU usage is more level, a lower limit or interval may be possible.
It also works for us because the session is saved in the database, and killing the process will not be noticeable by the end- user once the site spins back up again. However, iIf your site is dependent on IIS storing session variables, killing the process may end up causing more problems than it’s worth.