Partilhar via


How to: Change the Settings for the Request Throttling System

Applies to: SharePoint Foundation 2010

This topic describes how to programmatically change the settings of the performance monitoring and HTTP request throttling system in Microsoft SharePoint Foundation.

Persistence of the Settings

Each SharePoint Foundation web application has its own performance monitoring and request throttling settings. The settings are persisted in the configuration database as an SPHttpThrottleSettings object that is the value of the HttpThrottleSettings property of the web application.

What You Can and Cannot Change

You cannot change the following aspects of the system:

  • Health scores are always integers from 0 to 10, with the lowest score being the healthiest and the highest being the least healthy.

  • The health score of a given monitor is based on a time-weighted average of samples of the counter that is being monitored, and you cannot change the weighting algorithm. (However, there is a way to turn off the use of multiple samples. See the next bulleted list.)

  • A worker process is given an overall health score that is equal to the least healthy score of any of the web application’s registered monitors.

  • A worker process goes into throttling mode only when it has a health score of 10; that is, at least one of the performance monitors has a health score of 10.

  • A worker process goes into second stage throttling only when it has a health score of 10 for at least 60 seconds. This means that, for at least 60 seconds continuously, there has been some monitor or other with a score of 10. However, it is not necessary that a given monitor be continuously at state 10. If monitor A has a score of 10 for a 45-second period, and monitor B has a score of 10 for an overlapping period of 45 seconds, there may be a 60-second span in which there is always at least one monitor that has score 10. In that scenario, the worker process enters second stage throttling.

You can programmatically change the following aspects of the system:

  • Whether throttling is enabled for a web application. See Changing Properties of SPHttpThrottleSettings later in this topic.

  • How frequently the monitored counters are sampled. All counters that are being monitored by a specific web application must be sampled with the same frequency. See Changing Properties of SPHttpThrottleSettings later in this topic.

  • How many samples of each counter are used to calculate the weighted average of values for each counter. Setting this value to 1 effectively turns off averaging. All monitors of a specific web application must use the same number of samples. See Changing Properties of SPHttpThrottleSettings later in this topic.

  • Which of the Windows Server 2008 counters are monitored. For more information, see How to: Register or Deregister a Performance Counter.

  • Which kinds of requests are never blocked, what kinds are blocked, and whether they are blocked in first stage throttling or second stage throttling. For more information, see How to: Create and Register or Deregister a Request Classifier.

  • The health score calculator that is associated with a particular monitor. For more information, see How to: Create, Modify, and Change a Bucket-Style Health-Score Calculator.

  • The boundaries of the buckets (subranges of values) that a health score calculator uses to assign a score to a given counter value (or function of values). (This point applies only to standard bucket-style health score calculators.) For more information, see How to: Create, Modify, and Change a Bucket-Style Health-Score Calculator.

Changing Properties of SPHttpThrottleSettings

Programmatically enabling or disabling request throttling poses no special challenges. Neither does changing the number of samples that are used to calculate a weighted average or changing the frequency with which counters are sampled. The following code shows the program.cs file of a console application project. The Microsoft Visual Studio project requires a reference to Microsoft.SharePoint.dll, which is located in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI. The following code changes the frequency with which samples are taken to 10 seconds from the default of 5 seconds, enables throttle monitoring for the parent web application, and changes the number of samples to 5 from the default of 12. Notice that Update() is called to save the changes to the configuration database.

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;

namespace Contoso.SharePoint.Utilities
{
    class ThrottleSettingsChanger
    {
        static void Main(string[] args)
        {
            Uri webApplicationUri = new Uri("Http://localhost/");
            SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);

            SPHttpThrottleSettings throttleSettings = SPHttpThrottleSettings.GetHttpThrottleSettings(webApplication);

            throttleSettings.RefreshInterval = 10000;
            throttleSettings.PerformThrottle = true;
            throttleSettings.NumberOfSamples = 5;
            throttleSettings.Update();            
        }
    }
}

See Also

Concepts

Request Throttling