Share via


How to: Create a New Request Classifier

Applies to: SharePoint Foundation 2010

This topic describes how to create a new kind of HTTP request classifier to extend the performance monitoring and request throttling system of Microsoft SharePoint Foundation.

Request Classifier Classes

Microsoft SharePoint Foundation has a few built-in types of request classifiers. Each of them classifies HTTP requests based on a particular set of characteristics of the requests. The following table shows the classes and the kind of request category each of them can be used to define.

Type

Category

SPHttpFileExtensionThrottleClassifier

Requests for resources with a specified file name extension

SPHttpHeaderThrottleClassifier

Requests that contain a specified header or have a specified value for a specified header

SPHttpUserAgentAndMethodClassifier

Requests that have a specified user agent or that use a specified HTTP method

SPSearchCrawlingRequestClassifier

Requests that come from search crawlers

It is likely that you can create any kind of classifier object you need by using one or another of these classes. However, if none of these classes meets your needs, you can derive a new request classifier class from the SPRequestThrottleClassifier class.

Tip

Remember that you do not need a new class for every type of request whose throttling needs to be managed. For example, SharePoint Foundation does not have a built in SPHttpDOCXThrottleClassifier to manage throttling of requests for .docx files and a SPHttpSVCThrottleClassifier to manage requests for REST (Representational State Transfer) services. Instead, it has a more generic SPHttpFileExtensionThrottleClassifier. Specific objects of this class can be created for specific file name extensions. Hence, you only need to derive a new class from SPRequestThrottleClassifier if there is a category of request characteristic that is not accounted for by any of the built in classes that are derived from SPRequestThrottleClassifier.

Deriving a New Class

At a minimum there are two tasks to creating a new classifier class and two more tasks that are almost always needed. The minimum tasks are as follows:

  • Override the ThrottleLevel property, which specifies in what stage of throttling, if any, matching requests are blocked. You can specify FirstStage (the worker process is in poor health), SecondStage (the worker process has been in poor health for at least 60 seconds), or Never. (The system default for requests that do not match any classifier is to block them in first stage, so you must specifically create a classifier object with a throttle level of Never for any requests that should be exempted from throttling.) The ThrottleLevel property is read-only. If every object of your class should always have the same throttle level, implement the property to always return that level. Otherwise, implement it to return the value of a backing field, which is set by a class constructor and which may have a default value.

  • Override the Match(HttpRequest) method. This method contains the logic that determines whether the classifier object classifies an HTTP request as a match. So it effectively defines the "category" of the classifier in the sense used in the table earlier in this topic. For examples, see the Match methods of the four classes in the table.

The two additional tasks that are almost always needed are as follows:

  • Add more properties and helper methods as needed by the logic in your override of the Match(HttpRequest) method. Again, see the classes in the table for examples.

  • Add a constructor for the class. Typically, you will need the constructor to set the value of the ThrottleLevel property and possibly also to set the value of other properties in your class.

See Also

Tasks

How to: Create and Register or Deregister a Request Classifier

Concepts

Request Throttling