Improving the Availability
of Your Website in
ASP.NET MVC4
GABRIEL ENEA
MICROSOFT MVP – ASP.NET/IIS
TECHNICAL LEAD – MAXCODE
@DOTNET18 / GABRIELENEA.BLOGSPOT.COM

CODECAMP IASI, 10 NOV 2012
How ASP.NET Requests Are
Processed by the Thread Pool?
How Requests Are Processed by
the Thread Pool



 free
                            IIS, ASP.NET Requests,
                            Thread Pool, .NET Fx
How Requests Are Processed by
the Thread Pool
  R
  e
  q
  u
  e
  s
  t




 free
                            IIS, ASP.NET Requests,
                            Thread Pool, .NET Fx
How Requests Are Processed by
the Thread Pool
  R
  e
  q
  u
  e
  s
  t




 busy     free
                            IIS, ASP.NET Requests,
                            Thread Pool, .NET Fx
How Requests Are Processed by
the Thread Pool
  R
  e
  q
  u
  e
  s
  t




 busy
                                               IIS, ASP.NET Requests,
                                               Thread Pool, .NET Fx




      Web Services (long running operations)
How Requests Are Processed by
the Thread Pool
  R
  e
  q
  u
  e                    Request Queue
  s
  t




 busy
                                       IIS, ASP.NET Requests,
                                       Thread Pool, .NET Fx




        Web Services
How Requests Are Processed by
the Thread Pool
  R
  e
  q
  u
  e                    Request Queue
  s
  t




 busy
                                       IIS, ASP.NET Requests,
                                       Thread Pool, .NET Fx




        Web Services
How Requests Are Processed by
the Thread Pool                              3
                                             0
                                             5
  R
  e
  q
  u
  e                    Request Queue   HTTP 503 Error
  s                                    Server Too Busy
  t




 busy
                                          IIS, ASP.NET Requests,
                                          Thread Pool, .NET Fx




        Web Services
How Requests Are Processed by
the Thread Pool       R
                      e
                      q
                      u
                      e
                      st
                                            3
                                            0
                                            5
  R
  e
  q
  u
  e                   Request Queue   HTTP 503 Error
  s                                   Server Too Busy
  t




               free
                                         IIS, ASP.NET Requests,
                                         Thread Pool, .NET Fx




       Web Services
How Requests Are Processed by
the Thread Pool
What Can We Do to Improve the
Availability?
What Can We Do to Improve the
Availability?
Using Asynchronous methods

  R
  e
  q
  u
  e
  s
  t




        free
                              IIS, ASP.NET Requests,
                              Thread Pool, .NET Fx
 busy




               Web Services
.NET Asynchronous Operations patterns
.NET Asynchronous Operations
patterns
    Synchronous code




    .NET 1.0: Asynchronous Programming Model (APM) pattern
.NET Asynchronous Operations
patterns
    Synchronous code




    .NET 2.0: Event-based Asynchronous Pattern (EAP)
.NET Asynchronous Operations
patterns
    Synchronous code




    .NET 4.0: Task-based Asynchronous Pattern (TAP)
.NET Asynchronous Operations
patterns      Synchronous code
                 




    .NET 1.0:                               compare

                        .NET 4.0:




    .NET 2.0           .NET 4.5
                             async, await
ASP.NET MVC
Asynchronous Operations Support
ASP.NET MVC - Asynchronous
Operations Support


    MVC3
        AsyncController
        AsyncManager
    MVC4
        Task-based asynchronous action methods
DEMO
DEMO



    Bingoogle – Dual Search Engine
    ASP.NET MVC3 -> MVC4
Guidelines:
When to use synchronous or
asynchronous action methods?
When to use synchronous action
methods?


    The operations are simple or short-running
    Simplicity is more important than efficiency
    The operations are CPU-bound
When to use asynchronous action
methods? (1)

    Asynchronous methods available and using .NET 4.5
    The operations are network-bound or I/O-bound
    Parallelism is more important than simplicity of code
When to use asynchronous action
methods? (2)

    You want to provide a mechanism that lets users cancel
     a long-running request
    Switching threads out weights the cost of the context
     switch
    Testing shows that the blocking operations are a
     bottleneck in site performance
Server Configuration for High
Concurrency/Latency Web Service Calls
Server Configuration for High
Concurrency/Latency Web Service Calls
    aspnet.config

 <configuration>
   <system.web>
     <applicationPool
         maxConcurrentRequestsPerCPU="5000"
         maxConcurrentThreadsPerCPU="0"          HTTP.sys queue limit
         requestQueueLimit="5000" />
   </system.web>
 </configuration>
Improving the Availability of Your
Website in ASP.NET MVC4

                 Questions?
Resources



 Ask Google or start with..
    MSDN - Asynchronous Programming with Async and Await
    www.asp.net - Using Asynchronous Methods in ASP.NET MVC 4
    Channel9 - Mads Torgersen: Inside C# Async
Improving the Availability of Your
Website in ASP.NET MVC4
       Please fill the evaluation
       form


GABRIEL ENEA
MICROSOFT MVP – ASP.NET/IIS
TECHNICAL LEAD – MAXCODE
@DOTNET18 / GABRIELENEA.BLOGSPOT.COM
Diamond Sponsors




Platinum Sponsors                    Gold Sponsors


Training Partners   Media Partners          Other Partners

Improving the availability of your website

  • 1.
    Improving the Availability ofYour Website in ASP.NET MVC4 GABRIEL ENEA MICROSOFT MVP – ASP.NET/IIS TECHNICAL LEAD – MAXCODE @DOTNET18 / GABRIELENEA.BLOGSPOT.COM CODECAMP IASI, 10 NOV 2012
  • 2.
    How ASP.NET RequestsAre Processed by the Thread Pool?
  • 3.
    How Requests AreProcessed by the Thread Pool free IIS, ASP.NET Requests, Thread Pool, .NET Fx
  • 4.
    How Requests AreProcessed by the Thread Pool R e q u e s t free IIS, ASP.NET Requests, Thread Pool, .NET Fx
  • 5.
    How Requests AreProcessed by the Thread Pool R e q u e s t busy free IIS, ASP.NET Requests, Thread Pool, .NET Fx
  • 6.
    How Requests AreProcessed by the Thread Pool R e q u e s t busy IIS, ASP.NET Requests, Thread Pool, .NET Fx Web Services (long running operations)
  • 7.
    How Requests AreProcessed by the Thread Pool R e q u e Request Queue s t busy IIS, ASP.NET Requests, Thread Pool, .NET Fx Web Services
  • 8.
    How Requests AreProcessed by the Thread Pool R e q u e Request Queue s t busy IIS, ASP.NET Requests, Thread Pool, .NET Fx Web Services
  • 9.
    How Requests AreProcessed by the Thread Pool 3 0 5 R e q u e Request Queue HTTP 503 Error s Server Too Busy t busy IIS, ASP.NET Requests, Thread Pool, .NET Fx Web Services
  • 10.
    How Requests AreProcessed by the Thread Pool R e q u e st 3 0 5 R e q u e Request Queue HTTP 503 Error s Server Too Busy t free IIS, ASP.NET Requests, Thread Pool, .NET Fx Web Services
  • 11.
    How Requests AreProcessed by the Thread Pool
  • 12.
    What Can WeDo to Improve the Availability?
  • 13.
    What Can WeDo to Improve the Availability?
  • 14.
    Using Asynchronous methods R e q u e s t free IIS, ASP.NET Requests, Thread Pool, .NET Fx busy Web Services
  • 15.
  • 16.
    .NET Asynchronous Operations patterns  Synchronous code  .NET 1.0: Asynchronous Programming Model (APM) pattern
  • 17.
    .NET Asynchronous Operations patterns  Synchronous code  .NET 2.0: Event-based Asynchronous Pattern (EAP)
  • 18.
    .NET Asynchronous Operations patterns  Synchronous code  .NET 4.0: Task-based Asynchronous Pattern (TAP)
  • 19.
    .NET Asynchronous Operations patterns Synchronous code   .NET 1.0: compare  .NET 4.0:  .NET 2.0  .NET 4.5  async, await
  • 20.
  • 21.
    ASP.NET MVC -Asynchronous Operations Support  MVC3  AsyncController  AsyncManager  MVC4  Task-based asynchronous action methods
  • 22.
  • 23.
    DEMO  Bingoogle – Dual Search Engine  ASP.NET MVC3 -> MVC4
  • 24.
    Guidelines: When to usesynchronous or asynchronous action methods?
  • 25.
    When to usesynchronous action methods?  The operations are simple or short-running  Simplicity is more important than efficiency  The operations are CPU-bound
  • 26.
    When to useasynchronous action methods? (1)  Asynchronous methods available and using .NET 4.5  The operations are network-bound or I/O-bound  Parallelism is more important than simplicity of code
  • 27.
    When to useasynchronous action methods? (2)  You want to provide a mechanism that lets users cancel a long-running request  Switching threads out weights the cost of the context switch  Testing shows that the blocking operations are a bottleneck in site performance
  • 28.
    Server Configuration forHigh Concurrency/Latency Web Service Calls
  • 29.
    Server Configuration forHigh Concurrency/Latency Web Service Calls  aspnet.config <configuration> <system.web> <applicationPool maxConcurrentRequestsPerCPU="5000" maxConcurrentThreadsPerCPU="0"  HTTP.sys queue limit requestQueueLimit="5000" /> </system.web> </configuration>
  • 30.
    Improving the Availabilityof Your Website in ASP.NET MVC4 Questions?
  • 31.
    Resources Ask Googleor start with..  MSDN - Asynchronous Programming with Async and Await  www.asp.net - Using Asynchronous Methods in ASP.NET MVC 4  Channel9 - Mads Torgersen: Inside C# Async
  • 32.
    Improving the Availabilityof Your Website in ASP.NET MVC4 Please fill the evaluation form GABRIEL ENEA MICROSOFT MVP – ASP.NET/IIS TECHNICAL LEAD – MAXCODE @DOTNET18 / GABRIELENEA.BLOGSPOT.COM
  • 33.
    Diamond Sponsors Platinum Sponsors Gold Sponsors Training Partners Media Partners Other Partners