Asp.net site request timeout

Source: Internet
Author: User

Recently, due to attacks and request timeout, I had to study IIS again.

About iis related stuff, personal strong recommendation: http://www.iis.net/

When the request times out, we think of a high traffic volume or a server that cannot hold the spam program. In general, we naturally look at the problem with the program, so we started to study timeout. (Note: Do not deny the existence of attacks. Heavy Rain traffic only falls down from the sky. Otherwise, it is artificial. Believe in everything that is falling in the sky .)

This problem may be caused by the number of requests that can be executed by ASP. NET-restricted working threads and port completion threads.

Generally, a Web service call uses a working thread to execute the request sending code and a completion port thread from the Web service to receive the callback. However, if the request is redirected or requires authentication, the call may use up to two working threads and two completed port threads. Therefore, you can exhaust the managed ThreadPool when multiple Web service calls occur at the same time.

For example, if the ThreadPool is limited to 10 worker threads and all 10 worker threads are executing the code that is waiting to be executed. This is because any work items queued up In the ThreadPool will be blocked until a thread becomes available and callback can never be executed.

Another potential competitionMaxconnectionParametersSystem. NetThe namespace is used to limit the number of connections. Generally, this restriction is applied as expected. However, if many applications try to make one more thread for a single IP address request, they may have to wait for available connections.

 

To solve these problems, you can adjust the following parameters in the Machine. config file that best suits you:

  • MaxWorkerThreads
  • MinWorkerThreads
  • MaxIoThreads
  • MinFreeThreads
  • MinLocalRequestFreeThreads
  • Maxconnection
  • ExecutionTimeout

To successfully resolve these problems, perform the following operations:

  • Limit the number of ASP. NET requests that can be executed at about 12 of each CPU.
  • Allows the Web Service callback to use threads freely in the ThreadPool.
  • Select the appropriate valueMaxconnectionsParameters. Your selection is based on the IP address and the number of AppDomains used.

Note:To limit the number of 12 ASP. NET requests per CPU, we recommend that you set this parameter to an arbitrary number. However, this restriction proves to be applicable to most applications.

 

 

MaxWorkerThreadsAnd MaxIoThreads

ASP. NET uses the following two configuration settings to limit the maximum number of working threads and the number of completed threads used:

<processModel maxWorkerThreads="20" maxIoThreads="20">

MaxWorkerThreadsParameters andMaxIoThreadsThe number of CPUs implicitly multiplied by the parameter. For example, if the maximum number of worker threads of Two processors is:

2 * maxWorkerThreads

 

 

 

MinFreeThreadsAnd MinLocalRequestFreeThreads

ASP. NET also contains the following defined worker threads and completion port threads that must be used to start remote requests or configure $ local requests:


If there are not enough threads available, the request is queued until enough threads can send requests freely. Therefore, ASP. NET will not execute more than one of the following requests at the same time:

( MaxWorkerThreads* Number of CPUs)- MinFreeThreads

Note:MinFreeThreadsParameters andMinLocalRequestFreeThreadsThe parameter is the number of CPUs that are not implicitly multiplied.

 

MinWorkerThreads

ASP. NET 1.0 Service Pack 3 and ASP. NET 1.1 also contain the following configuration settings to determine how many worker threads may obtain services that can be provided to remote requests immediately.

<processModel minWorkerThreads="1">

The thread controlled by this setting can create a working thread that is much faster than the default "thread adjustment" function created from CLR. This setting enables ASP.. NET can be suddenly filled in to the back-end server suddenly burst from the end of the client or any location similar to the request, the previous slow-down will cause a sudden increase in the number of requests in the queue due to ASP. NET Request queue service request.MinWorkerThreadsThe default value is 1. We recommend that youMinWorkerThreadsSet the parameter value to the following value.

minWorkerThreads = maxWorkerThreads / 2

By default,MinWorkerThreadsThe parameter does not exist in the Web. config file or the Machine. config file. This setting is implicitly multiplied by the number of CPUs.

 

Maxconnection

MaxconnectionThe parameter determines how many IP addresses can be connected. This parameter is displayed as follows:

<connectionManagement>    <add address="*" maxconnection="2">    <add address="65.53.32.230" maxconnection="12"></connectionManagement>

The parameter settings discussed in this article are all at the process level. However,MaxconnectionThe parameter settings are applied to the AppDomain level. By default, because this setting applies to AppDomain level, you can create two connections up to a specific IP address from each AppDomain in your process.

 

ExecutionTimeout

ASP. NET uses the following configuration settings to limit the request execution time:


You can also useServer. ScriptTimeoutAttribute to set this restriction.

Note:If you addExecutionTimeoutParameter value, you may have to modifyProcessModel responseDeadlockIntervalParameter settings.

 

Suggestions

The settings recommended in this section may not apply to all applications. However, the following additional information can help you make adjustments.

If you call a single IP address of a Web service to each ASPX page from Microsoft, we recommend that you use the following configuration settings:

  • SetMaxWorkerThreadsParameters andMaxIoThreadsThe parameter value is100.
  • SetMaxconnectionParameter Value12 *N(WhereNIs the number of CPUs you have ).
  • SetMinFreeThreadsParameter Value88 *N,MinLocalRequestFreeThreadsParameters76 *N.
  • SetMinWorkerThreadsTo50. RememberMinWorkerThreadsIt is not in the configuration file by default. You must add it.

Some of these suggestions involve a simple formula involving the number of CPUs on the server. Value of the variable type, which indicates that the number of CPUs in the formula isN. If you have hyper-threading enabled for these settings, you must use the number of logical CPUs instead of the number of physical CPUs. For example, if you have a quad-processor server with hyper-threading enabled,NIs8Instead4.

Note:When you use this configuration, You can execute the maximum value of 12 ASP. NET requests for each CPU at the same time, because100 88 = 12. Therefore, at least 88 *NAuxiliary thread and 88 *NThe completion port thread is available for other usage (such as Web Service callback ).

For example, you have a server with four processors and with hyper-threading enabled. Based on these formulas, you can use the configuration settings mentioned in this article.

<system.web><processModel maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>

In addition, when you use this configuration, 12 connections are available for each AppDomain of each cpu ip address. Therefore, in the following circumstances, few requests are waiting for connection, and when ThreadPool is used up:

  • There can be only one application (AppDomain) on the Web host ).
  • Each request on the ASPX page sends a Web service request.
  • All requests use the same IP address.

However, you may use too many connections when using this configuration that involves one of the following values:

  • Request multiple IP addresses.
  • The request will be redirected (302 Status Code ).
  • The request requires authentication.
  • Send a request from multiple AppDomains.

It is a good idea in these solutions.MaxconnectionParameter and high value:MinFreeThreadsParameters andMinLocalRequestFreeThreadsThe parameter uses a lower value.

 

Reference connection:

Http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/cpu

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.