This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20310|Reply: 0

[ASP.NET] ASP.NET use asynchronous controllers in MVC

[Copy link]
Posted on 4/1/2018 3:20:59 PM | | |
Thread pool

I have always wanted to rewrite the project to asynchronous, but ASP.NETMVC3 is too cumbersome to write, .NET 4.5 and ASP.NET MVC code is relatively simple, MS seems to have always liked to do this, every mature thing, it has to evolve several versions to tend to standardize. ASP.NET why do you need to use asynchronous in MVC, IIS has a thread pool to process user requests, when a new request comes, the threads in the pool will be scheduled to process the request, however, but when the concurrency is high, the threads in the pool can no longer meet so many requests, and every thread in the pool is busy when processing the request, the thread processing the request will be blocked, and the thread cannot provide services to another request, if the request queue is full, the web The server rejects the request and is in an HTTP 503 busy state. If you are dealing with some high latency, such as network operations, most of these threads just wait for the state and do nothing most of the time, such threads can use asynchronous programming to make better use of it.

Asynchronous processing

For example, if a request generates a network call that takes two seconds to complete, the request is madeIt takes two seconds to execute both synchronously and asynchronously。 ButDuring an asynchronous call, the server does not block the response to other requests while waiting for the first request to complete。 Therefore, when there are many requests calling long-running operations, asynchronous requests can prevent requests from queuing. In .NET 4.5, the maximum thread pool is 5000, and the await and async keywords have also been added in .NET 4.5 to simplify asynchronous programming.

Synchronous or asynchronous (excerpt from MSDN)

  • Typically, sync pipelines are used when the following conditions are met:
  • Simple operation or short run time.
  • Simplicity is more important than efficiency.
  • This operation is primarily CPU operations rather than operations that involve a lot of disk or network overhead. Using an asynchronous operation method for CPU-bound operations doesn't provide any benefit and also results in more overhead.

In general, asynchronous pipelines are used when the following conditions are met:

  • Operations are network-bound or I/O-bound rather than CPU-bound.
  • Tests have shown that blocking operations are a bottleneck to site performance, and by using asynchronous methods for these blocking calls, IIS can serve more requests.
  • Parallelism is more important than simplicity of code.
  • You want to provide a mechanism that allows users to cancel long-running requests.

ASP.NET use asynchronous controllers in MVC






Previous:WPF mvvm framework stylet document translation and learning materials
Next:[Windows API] Code Assistant for C# Query API [with source code]
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com