https://msdn.microsoft.com/zh-cn/library/ee728598 (v=vs.98). aspx
On the WEB server, the. NET Framework maintains a thread pool for servicing ASP. When a request arrives, the thread in the pool is dispatched to process the request. if the request is synchronized, the thread that processes the request is blocked when the request is processed, and the thread cannot service another request.
This may not be a problem because the thread pool can be set large enough to accommodate many blocked threads.However, there is a limit to the number of threads in the thread pool. in large applications that handle multiple long-running requests at the same time, all available threads may be blocked. thread starvation. " > This situation is called "insufficient thread". If the request queue is full, the WEB server rejects the request and is in the HTTP 503 state (the server is too busy).
Handling Asynchronous Requests
In applications where there may be a shortage of threads, you can configure the processing of operations asynchronously.The asynchronous request is the same processing time that is required to synchronize the request. For example, if a request generates a network call that takes two seconds to complete, it takes two seconds for the request to execute synchronously or asynchronously.
When you invoke an asynchronous operation, the following steps are performed:
The WEB server obtains a thread from the thread pool (worker thread) and schedules it to process incoming requests. This worker thread initiates an asynchronous operation.
Return this worker thread to the thread pool to service another WEB request.
Notifies ASP when an asynchronous operation is complete.
The WEB server gets a thread from the thread pool (possibly a different thread from the thread that initiated the asynchronous operation) to handle the remainder of the request, including rendering the response.
Shows the asynchronous Pattern.
Select a synchronous action method or an asynchronous action method
This section lists guidelines for when to use synchronous action methods or asynchronous action methods. This is just a few guidelines; You must examine each application individually to determine whether the asynchronous operation method can help improve performance.
Typically, you use a synchronization pipeline when the following conditions are true:
-
The operation is simple or has a short running time.
-
Simplicity is more important than efficiency.
-
This operation is primarily a CPU operation rather than a large amount of disk or network overhead.
Typically, an asynchronous pipeline is used when the following conditions are met:
-
-
Test shows that blocking operations are a bottleneck for site performance and that IIS can service more requests by using asynchronous action methods for these blocking calls.
-
parallelism is more important than the simplicity of code.
-
you want to provide a mechanism for users to cancel long-running requests.
The downloaded sample demonstrates how to use the asynchronous action method effectively. The sample program calls the Sleep method to simulate a long-running process. There are few product applications that show the benefits of using asynchronous operation methods so clearly.
You should test your application to determine whether an async method can provide performance benefits.In some cases, it may be better to increase the maximum number of IIS concurrent requests per CPU and the maximum number of concurrent threads per CPU.asp.net thread Usage on IIS 7.0 and 6.0 on Thomas Marquardt ' s blog. " > For more information on ASP., see the article on the Thomas Marquardt blog asp.net thread Usage on IIS 7.0 and 6.0 (ASP. NET thread in IIS 7.0 and 6.0 Usage on the application). shoul D My database calls be asynchronous? On Rick Anderson ' s blog. " > For more information about when to perform asynchronous database calls, see the articles on the Rick Anderson blog should My database calls be asynchronous? (should my database call be asynchronous?) )。
Very few applications require that all operation methods be asynchronous. In general, converting a small number of synchronous operations to asynchronous methods can significantly increase the amount of work required.
Asynchronous vs. Synchronous selection