Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using async with ASP.NET MVC 5

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 101
    Comment on it

    ASP.NET has a pool of threads to service incoming requests. Once a new request is received a new thread is picked from the thread pool to service this request and this thread cannot serve any other request until the current request gets completed.
    And if this request is long running, then the thread is blocked until the request is completed. The async actions are useful only when you are performing such kind of I/O bound operations such as remote server calls.
    The advantage of the async approach is that during the execution of long running method, ASP.NET worker thread is not used.
    Thus use of async action leads to improvement in the performance and responsiveness of an application.


    In the .NET 4.5 the default maximum size of the thread pool is 5,000 threads. Though we can increase the size of this thread pool but it is better to avoid it and use async feature for better use of threads.

    Below we show how the async approach is better than traditional approach:

    1) Once a request hits the action, ASP.NET takes a thread from the thread pool and request processing starts.


    2) The method invoked during the request is a blocking call.


    And now we will see how the async approach is different:

    1) Once a request hits the action, ASP.NET takes a thread from the thread pool and request processing starts.


    2) The method invoked during request processing returns immediately. An I/O completion port is registered and the thread is released to the thread pool.After some time when the operation completes, the I/O Completion port is notified following which another thread is drawn from the thread pool which finishes returning the view.
    As you can see in the async scenario ASP.NET worker threads are quickly released. So if you have an application that has a lot of concurrent calls that are network or CPU intensive using the asyn approach will result in performance enhancement.

    Ref : http://www.asp.net/mvc/overview/performance/using-asynchronous-methods-in-aspnet-mvc-4

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: