Understanding Searching Timeouts
Timeouts affect whether our searches will finish completely or return partial results. In addition to the limits imposed by the server, the client has the ability to request specific timeout behaviors as well.
Precedence of Timeouts
Within the DirectorySearcher class are a number of members that represent a timeout value of some type or another. It can often be confusing to determine exactly when each timeout value is used and what precedence each has. In this section, we will hopefully dispel some of that confusion.
Let's start by examining the available timeout settings:
- ClientTimeout
- ServerPageTimeLimit
- ServerTimeLimit
ClientTimeout
This TimeSpan represents the maximum amount of time that the client will wait for the server to return results before abandoning the search and returning no results. By default in SDS, this is set to wait indefinitely. If a TimeSpan greater than zero is provided, the client will wait the minimum of this value, or until an administrative server timeout is generated. Clients should set this to a reasonable value when expecting particularly long searches.
ServerPageTimeLimit
When used in conjunction with a paged search (see the section Returning Many Results with Paged Searches, in Chapter 4), this TimeSpan represents the maximum amount of time that the server should spend generating search results for a particular search page, before returning it to the client. As such, it is used only when searching for large result sets greater than the MaxPageSize that use paging (usually 1,000 results). Values greater than the MaxQueryDuration will essentially be ignored, as that will become the limiting factor per page. By default, this is set to wait indefinitely, so this means that in practice, the MaxQueryDuration will be used.
ServerTimeLimit
This TimeSpan specifies the maximum amount of time that the server will wait for a search to complete. If this value is exceeded, only the results accumulated to that point will be returned. By default, SDS is set to wait indefinitely. In practice, the limiting factor is the server's administrative LDAP search time limit of 120 seconds (MaxQueryDuration). All nonpaged searches must complete before the minimum of the ServerTimeLimit or MaxQueryDuration (the default is 120 seconds), or only the results accumulated to that point will be returned. Paged searches are not affected by this value.
Nonpaged Searches
When using a nonpaged search (i.e., PageSize equals zero), there are only three arbitrators of when a search will end. Table 5.2 summarizes these settings in a concise format.
Timeout Operator |
Default Value |
Precedence |
Notes |
---|---|---|---|
MaxQueryDuration |
120 seconds |
First |
This is an administrative limit found on the LDAPAdminLimit attribute. It is the maximum time any nonpaged search will be executed before the server generates a timeout. While it can be changed, it is not advisable to change this value from the default. |
ServerTimeLimit |
Indefinite |
Second |
Values larger than MaxQueryDuration will essentially be ignored, since the MaxQuery-Duration will be the limiting factor. |
ClientTimeout |
Indefinite |
Third |
The ServerTimeLimit takes precedence over this setting, so any value specified larger than the ServerTimeLimit will essentially be ignored. |
Paged Searches
For a paged search (i.e., PageSize is greater than zero), there are again three arbitrators of when a search will end. Table 5.3 summarizes these settings.
Timeout Operator |
Default Value |
Precedence |
Notes |
---|---|---|---|
ServerPageTimeLimit |
Indefinite |
First |
The ServerPageTimeLimit controls how much time the server will spend collecting an individual page. It does not control how long the entire search will last. A paged search will continue for as long as there are result pages, until it is finished. |
ClientTimeout |
Indefinite |
Second |
During a particularly long paged search, the client has the option of abandoning it using this timeout. |
MaxQueryDuration |
120 seconds |
Third |
This limit does not come into effect in practice very often, because this limit is applied per page and not per search. |
Optimizing Search Performance
|