The important function of web server is the ability to limit the CPU usage for a specific site, otherwise one website can use all the CPU resources, that may be unacceptable especially for shared hosting environment. In IIS  7.0 (Internet Information Services) and earlier you could use CPU monitoring feature only to stop a worker process for a few minutes if it consumes too much CPU resources. Full CPU load adjustment has been implemented only in IIS 8.0 (Windows Server 2012 and higher). CPU Throttling feature allows to limit the maximum CPU resources available for each IIS application pool instead of terminating the worker process.

In this article we will show you, guys, how to limit CPU Usage for the Application Pool on IIS 8 and higher.

Open Internet Information Services (IIS) Manager (%systemroot%\system32\inetsrv\iis.msc), expand the server and go to Application Pools branch. IIS CPU Throttling settings is located in the application pool configuration.

Tip. To set separate maximum CPU utilization for each IIS application (website), you need to configure each application to use its own App Pool.

  • If you want to enable restriction for the one particular application pool, you need to select it from the list and go to Advanced Settings.
  • If it is necessary to set the default limit for all pools, go to the section Set Application Pool Defaults.
advanced settings IIS 8

In the Advanced Settings dialog box, navigate to the CPU section, where we are interested in the following settings:

  • Limit — the maximum percentage of CPU time that the worker processes in an application pool can use. If this value is exceeded, performed the action specified in the Limit Action field. In IIS 8 percentage is defined in thousandths of a percent (1/ 1000 of %), (for example, to set CPU limit usage to 30%, you must specify 30000 in the Limit value field. In IIS 8.5 value is specified as a usual percentage. To disable CPU limiting, set Limit to 0.
  • Limit Action — action that must take place with the pool when it reaches the CPU usage limit;
  • Limit Interval (minutes) — period of testing and resetting the result of load monitoring (worker processes is prevented from restarting until Limit Interval expires). This parameter is not used for throttling and is designed primarily for compatibility with previous versions of IIS.
advanced settings CPU IIS 8

Tip. These settings are apply to the user on whose behalf the application pool is running. By default, each pool has a unique account and load for each pool is managed separately. If you use a dedicated account with multiple application pools are running, then they will have the same settings. Load adjustment applies not only to the primary working process, but also to all child processes, if they exist.

After setting the limit in the Limit Action field it is necessary to choose the action that should take place with the pool when it reaches the limit:

  • NoAction – No action is taken, event log entry is generated when the CPU limit is exceeded
  • KillW3wp (Kill worker processes) – the application pool workflow that exceed their CPU limit is forced shut down for the time defined in Limit Interval, event log entry is generated
  • Throttle – the application pool worker CPU usage is throttled to the value set in Limit field. Limit interval is not used and event log is generated
  • ThrottleUnderLimit – the CPU consumption is restricted only if the server is highly loaded. If the CPU is idle the application pool may exceed CPU limit.  Limit interval is not used.
advanced settings CPU noaction IIS 8

You can also configure CPU Throttling using the console utility appcmd. For example to enable throttling for the DefaultAppPool at 20% load, it is necessary to open a command prompt and run the command:

%systemroot%\system32\inetsrv\appcmd set apppool DefaultAppPool /cpu.limit:20000 /cpu.action:Throttle
defaultapppol IIS 8

If you want to enable restriction of CPU usage for all IIS pools:

%systemroot%\system32\inetsrv\appcmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.cpu.limit:20000 /cpu.action:Throttle /commit:apphost

Thus it is possible to flexibly adjust the load of server processor generated by web-applications. In conclusion, let me remind that the CPU Throttling is not used for reservation of CPU resources and applies only to the CPU load limit.