SlideShare a Scribd company logo
Rudi Benkovič rudib@whiletrue.com
While True, d.o.o.
www.whiletrue.com
A very simple read-only MVC application.
As per ASP.NET MVC.NET’s guidelines:
 ASP.NET MVC 1.0
     Also MVCFutures – official addons for MVC
    LINQ-SQL

    IIS7

    SQL Server

ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
ASP.NET MVC Performance
Wow! IntelliSense!
ASP.NET MVC Performance
We’re testing response time, not overall
throughput – just one concurrent connection.
IIS7             ApacheBench
       ab.exe –n 100 –c 1 http://.../
Response time   Requests / second
        500ms               2
        250ms               4
        100ms               10
         50ms               20
         25ms               40
         15ms              66.6
         10ms              100
         5ms               200




Place your bets!
(Core2 Duo 2.5GHz, 4GB RAM, Win2008 64bit) 8 requests / second




                             Oops
A better “user experience”: responsive web application
1.
     System can respond to many concurrent
2.
     requests
     We can do more things in a single requests:
3.
     richer web applications
JetBrains dotTrace

     Run as Administrator
     IIS worker process: set CPU affinity to a single
     CPU
Expression links
Route itself


Name                  Default values
Expression link

    Html.BuildUrlFromExpression<AccountController>(a => a.UserHome(username))



    Name the action and the controller

    Url.Action(quot;UserHomequot;, quot;Accountquot;, new {username = username})



    Name the route

    Url.RouteUrl(quot;Userquot;, new { username = quot;joeuserquot; })



    Brute force

    string.Format(quot;User/{0}quot;, Url.Encode(username))
Time [ms for 200 links]
      390,0 (!)
20
18
16
                            13.6
14
12
10
                                             7.2
 8
 6
 4
 2
 0
     Expression            Action           Route
Why are variables that much slower?
Different code path for non-constants. We have to compile (!) the expression!
Simple syntax. But, how do we read data from such
objects?
Reading data from an anonymous class into
 RouteValueData (required). Overhead!
Passing multiple parameters can yield a
 significant overhead.
Pass data in a RouteValueDictionary!




Syntax isn’t nearly as nice, but is it worth it?
Time for 200 links [ms]
          390,0 (!)
 20
 18
 16
                          13.6
 14
 12                                         9.8
 10
                                                           7.2
  8
  6                                                                     3.8
  4
  2
  0
        Expression ction, anonymous Action, dictionary anonymous object dictionary
                 A                  class        Route,           Route,



As speed increases, so does the syntax and maintenance overhead!
Results:
8 requests / second => 25.5 requests / second

Replace anonymous classes with
 RouteValueDictionaries:

25.5 requests / second => 27 requests / second
Each LINQ-SQL
query calls
BuildQuery, which
seems to be time
consuming. Why?
Deffered evaluation

    The expression gets transformed into SQL only
    when we call such a method that demands data for
    its work.

    These transformations get cached inside the

    DBContext. Web applications can’t share
    contexts, so there is no effective caching
    getting done.
ToList() triggers the compilation of the query
Compile the expression tree into an SQL

    query and mapping methods. Store them as a
    function that is thread-safe and accepts a
    DBContext and query parameters.
Non-compiled LINQ-SQL query.
Static delegate that
                                              stores the compiled
                                                      query
It’s simple, really...




                         Static DLO


                                                   Return value




                         The original query
Usage: call the static function with the

    current DBContext
Additional feature: join more queries into one!
A lot of overhead source code. Uncompiled

    LINQ-SQL queries are terse, these just aren’t.
    Black magic – the original query won’t always

    work as-is. Exceptions from within LINQ-SQL
    that you can’t really debug.
    A compiled query has to always be called with

    the same instance of
    DataLoadOptions, otherwise it fails!
Simple generic, lambda syntax for queries

    parameters: only for up to three parameters!
    Otherwise you’ll need to declare a class for
    parameters.
Results:
25 requests / second => 52 requests / second

The difference isn’t as big as in real-world
 projects: we don’t have a lot of parameters
 for queries and the expressions are simple.
RenderPartial gets called 41 times from the Index
  view! Let’s optimize that by passing the
  enumeration to the view itself.




Somewhat defeats partial view’s intended usage, but...
41 calls to RenderPartial => three calls.

Results:
52 requests / second => 61.5 requests / second
URLs for MVC applications are typically

    static: they don’t change depending on the
    user/session/request.

    Let’s cache them!



    We wrote our own caching API that uses

    ASP.NET’s builtin memory cache.
Extend ASP.NET MVC’s UrlHelper into UrlHelperCached, add
  new cached methods for Action links.

Join all of data for a single link (action, controller, data) into a
   string and use that as the cache key.
UrlHelper doesn’t implement an interface and it’s methods
  aren’t virtual. We’ll add our own UrlHelperCached as a new
  UrlCached property by extending MVC’s classes:
  MasterPage, ViewPage, ViewUserControl.
Usage: inherit our View class in view’s definition
 and replace Url with UrlCached. That’s all!
Results:
61.5 requests / second => 76 requests / second


Real-world: as routing table gets longer and
 more parameters get passed around, the
 difference is even greater!
We can cache site statistics.

Here’s our little caching API that uses lambda
 syntax for cached values. A lot less code!
Cache stats and top voted news of all time:
76 requests/ second => 153 requests/ second.

Let’s also cache the main news display:
153 requests/ second => 400 requests / second.

Caching all DB data foregoes any SQL-LINQ or SQL
  connection initialization. Even less overhead with
  much faster response times.
Core2 Duo 2.53GHz, 4GB RAM, IIS7        Optimization only   Data caching
 450                                                                400
             Requests per second
 400
 350
 300
 250
 200                                                        153
 150
                                                      76
                                           61.5
 100                               52
                            27
                   25.5
  50     8
   0
Each of these optimization methods is in
 production: fast URL generation, compiled
 queries, URL caching, data caching.
                           The first alpha version
                           without any optimizations
                           ran at ~3 requests / second.
                           Today, the index page can
                           withstand ~800
                           requests/second on a
                           development webserver with
                           real world DB data. HTTP
                           concurrency = 8.
After a few uncomfortable moments of silence...


      Questions?
Ideas for ASP.NET MVC developers:

     Smarter view compiling. Let’s inline partial code
      for views. Or let’s write a new view engine.
     RenderPartials() method that accepts an
      enumeration and can also use a spacer view – like
      RoR.
     Builtin URL caching – why not? Or at least make
      interfaces for HTML and URL helpers.
Thanks to Simone Chiaretta for discovering a gross oversight
  on my part: I’ve done my benchmarks with ASP’s debug
  mode turned on. With regards to ASP.NET MVC 1.0, this
  disables its view engine’s internal cache for resolved paths to
  views. This makes specifying full paths to view irrelevant as
  far as performance is considered.

So, the following change won’t yield any performance yield
  with the debug attribute set to false
  (Web.config, compilation section).
All of the benchmarks have been re-run with debug turned
  off, the change before any optimizations have taken
  place is significant (6 req/s to 8 req/s). Any other
  changes to the performance due to the release mode
  other than view path resolving were basically non-
  existing or within the margin of error.

You can read Simone’s post at
  http://codeclimber.net.nz/archive/2009/04/22/how-to-improve-
  htmlhelper.renderpartial-performances-donrsquot-run-in-debug-mode.aspx

And, of course, run your production websites in
  release mode. :)

More Related Content

What's hot

CDC Stream Processing with Apache Flink
CDC Stream Processing with Apache FlinkCDC Stream Processing with Apache Flink
CDC Stream Processing with Apache Flink
Timo Walther
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
akhilsreyas
 
React Hooks
React HooksReact Hooks
React Hooks
Joao Marins
 
Reproducible bioinformatics for everyone: Nextflow & nf-core
Reproducible bioinformatics for everyone: Nextflow & nf-coreReproducible bioinformatics for everyone: Nextflow & nf-core
Reproducible bioinformatics for everyone: Nextflow & nf-core
Phil Ewels
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
NexThoughts Technologies
 
Protocol buffers
Protocol buffersProtocol buffers
Protocol buffers
Fabricio Epaminondas
 
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
confluent
 
Building robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and DebeziumBuilding robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and Debezium
Tathastu.ai
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
ritika1
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
InfluxData
 
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Jemin Huh
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
Dr. Awase Khirni Syed
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
VMware Tanzu
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
Mallikarjuna G D
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
TheCreativedev Blog
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
mohamed elshafey
 

What's hot (20)

CDC Stream Processing with Apache Flink
CDC Stream Processing with Apache FlinkCDC Stream Processing with Apache Flink
CDC Stream Processing with Apache Flink
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
React Hooks
React HooksReact Hooks
React Hooks
 
Reproducible bioinformatics for everyone: Nextflow & nf-core
Reproducible bioinformatics for everyone: Nextflow & nf-coreReproducible bioinformatics for everyone: Nextflow & nf-core
Reproducible bioinformatics for everyone: Nextflow & nf-core
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Protocol buffers
Protocol buffersProtocol buffers
Protocol buffers
 
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
 
Building robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and DebeziumBuilding robust CDC pipeline with Apache Hudi and Debezium
Building robust CDC pipeline with Apache Hudi and Debezium
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
 
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
Spring boot 를 적용한 전사모니터링 시스템 backend 개발 사례
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 

Similar to ASP.NET MVC Performance

Building production websites with Node.js on the Microsoft stack
Building production websites with Node.js on the Microsoft stackBuilding production websites with Node.js on the Microsoft stack
Building production websites with Node.js on the Microsoft stack
CellarTracker
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
oazabir
 
Nodejs + Rails
Nodejs + RailsNodejs + Rails
Nodejs + Rails
Michał Łomnicki
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
Bluegrass Digital
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Vladimir Bacvanski, PhD
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
Malam Team
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
Jarrod Overson
 
Advanced Asp.Net Concepts And Constructs
Advanced Asp.Net Concepts And ConstructsAdvanced Asp.Net Concepts And Constructs
Advanced Asp.Net Concepts And Constructs
Manny Siddiqui MCS, MBA, PMP
 
Mvc
MvcMvc
How To Scale v2
How To Scale v2How To Scale v2
How To Scale v2
Georgio_1999
 
Sherlock Homepage - A detective story about running large web services - WebN...
Sherlock Homepage - A detective story about running large web services - WebN...Sherlock Homepage - A detective story about running large web services - WebN...
Sherlock Homepage - A detective story about running large web services - WebN...
Maarten Balliauw
 
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Joonas Lehtinen
 
Real World Single Page App - A Knockout Case Study
Real World Single Page App - A Knockout Case StudyReal World Single Page App - A Knockout Case Study
Real World Single Page App - A Knockout Case Study
housecor
 
Drizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's ConferenceDrizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's Conference
Brian Aker
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
Espresso Logic
 
SharePoint 2010 Boost your farm performance!
SharePoint 2010 Boost your farm performance!SharePoint 2010 Boost your farm performance!
SharePoint 2010 Boost your farm performance!
Brian Culver
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
buildmaster
 

Similar to ASP.NET MVC Performance (20)

Building production websites with Node.js on the Microsoft stack
Building production websites with Node.js on the Microsoft stackBuilding production websites with Node.js on the Microsoft stack
Building production websites with Node.js on the Microsoft stack
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Nodejs + Rails
Nodejs + RailsNodejs + Rails
Nodejs + Rails
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
Advanced Asp.Net Concepts And Constructs
Advanced Asp.Net Concepts And ConstructsAdvanced Asp.Net Concepts And Constructs
Advanced Asp.Net Concepts And Constructs
 
Mvc
MvcMvc
Mvc
 
How To Scale v2
How To Scale v2How To Scale v2
How To Scale v2
 
Sherlock Homepage - A detective story about running large web services - WebN...
Sherlock Homepage - A detective story about running large web services - WebN...Sherlock Homepage - A detective story about running large web services - WebN...
Sherlock Homepage - A detective story about running large web services - WebN...
 
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaSc...
 
Real World Single Page App - A Knockout Case Study
Real World Single Page App - A Knockout Case StudyReal World Single Page App - A Knockout Case Study
Real World Single Page App - A Knockout Case Study
 
Drizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's ConferenceDrizzle Keynote at the MySQL User's Conference
Drizzle Keynote at the MySQL User's Conference
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
 
SharePoint 2010 Boost your farm performance!
SharePoint 2010 Boost your farm performance!SharePoint 2010 Boost your farm performance!
SharePoint 2010 Boost your farm performance!
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
 

Recently uploaded

How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
Sally Laouacheria
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
rajancomputerfbd
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 

Recently uploaded (20)

How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 

ASP.NET MVC Performance

  • 1. Rudi Benkovič rudib@whiletrue.com While True, d.o.o. www.whiletrue.com
  • 2. A very simple read-only MVC application.
  • 3. As per ASP.NET MVC.NET’s guidelines:  ASP.NET MVC 1.0  Also MVCFutures – official addons for MVC LINQ-SQL  IIS7  SQL Server 
  • 16. We’re testing response time, not overall throughput – just one concurrent connection.
  • 17. IIS7 ApacheBench ab.exe –n 100 –c 1 http://.../
  • 18. Response time Requests / second 500ms 2 250ms 4 100ms 10 50ms 20 25ms 40 15ms 66.6 10ms 100 5ms 200 Place your bets!
  • 19. (Core2 Duo 2.5GHz, 4GB RAM, Win2008 64bit) 8 requests / second Oops
  • 20. A better “user experience”: responsive web application 1. System can respond to many concurrent 2. requests We can do more things in a single requests: 3. richer web applications
  • 21. JetBrains dotTrace   Run as Administrator  IIS worker process: set CPU affinity to a single CPU
  • 23. Route itself Name Default values
  • 24. Expression link  Html.BuildUrlFromExpression<AccountController>(a => a.UserHome(username)) Name the action and the controller  Url.Action(quot;UserHomequot;, quot;Accountquot;, new {username = username}) Name the route  Url.RouteUrl(quot;Userquot;, new { username = quot;joeuserquot; }) Brute force  string.Format(quot;User/{0}quot;, Url.Encode(username))
  • 25. Time [ms for 200 links] 390,0 (!) 20 18 16 13.6 14 12 10 7.2 8 6 4 2 0 Expression Action Route
  • 26. Why are variables that much slower?
  • 27. Different code path for non-constants. We have to compile (!) the expression!
  • 28. Simple syntax. But, how do we read data from such objects?
  • 29. Reading data from an anonymous class into RouteValueData (required). Overhead!
  • 30. Passing multiple parameters can yield a significant overhead.
  • 31. Pass data in a RouteValueDictionary! Syntax isn’t nearly as nice, but is it worth it?
  • 32. Time for 200 links [ms] 390,0 (!) 20 18 16 13.6 14 12 9.8 10 7.2 8 6 3.8 4 2 0 Expression ction, anonymous Action, dictionary anonymous object dictionary A class Route, Route, As speed increases, so does the syntax and maintenance overhead!
  • 33. Results: 8 requests / second => 25.5 requests / second Replace anonymous classes with RouteValueDictionaries: 25.5 requests / second => 27 requests / second
  • 34. Each LINQ-SQL query calls BuildQuery, which seems to be time consuming. Why?
  • 35. Deffered evaluation  The expression gets transformed into SQL only when we call such a method that demands data for its work. These transformations get cached inside the  DBContext. Web applications can’t share contexts, so there is no effective caching getting done.
  • 36. ToList() triggers the compilation of the query
  • 37. Compile the expression tree into an SQL  query and mapping methods. Store them as a function that is thread-safe and accepts a DBContext and query parameters.
  • 39. Static delegate that stores the compiled query It’s simple, really... Static DLO Return value The original query
  • 40. Usage: call the static function with the  current DBContext
  • 41. Additional feature: join more queries into one!
  • 42. A lot of overhead source code. Uncompiled  LINQ-SQL queries are terse, these just aren’t. Black magic – the original query won’t always  work as-is. Exceptions from within LINQ-SQL that you can’t really debug. A compiled query has to always be called with  the same instance of DataLoadOptions, otherwise it fails!
  • 43. Simple generic, lambda syntax for queries  parameters: only for up to three parameters! Otherwise you’ll need to declare a class for parameters.
  • 44. Results: 25 requests / second => 52 requests / second The difference isn’t as big as in real-world projects: we don’t have a lot of parameters for queries and the expressions are simple.
  • 45. RenderPartial gets called 41 times from the Index view! Let’s optimize that by passing the enumeration to the view itself. Somewhat defeats partial view’s intended usage, but...
  • 46. 41 calls to RenderPartial => three calls. Results: 52 requests / second => 61.5 requests / second
  • 47. URLs for MVC applications are typically  static: they don’t change depending on the user/session/request. Let’s cache them!  We wrote our own caching API that uses  ASP.NET’s builtin memory cache.
  • 48. Extend ASP.NET MVC’s UrlHelper into UrlHelperCached, add new cached methods for Action links. Join all of data for a single link (action, controller, data) into a string and use that as the cache key.
  • 49. UrlHelper doesn’t implement an interface and it’s methods aren’t virtual. We’ll add our own UrlHelperCached as a new UrlCached property by extending MVC’s classes: MasterPage, ViewPage, ViewUserControl.
  • 50. Usage: inherit our View class in view’s definition and replace Url with UrlCached. That’s all!
  • 51. Results: 61.5 requests / second => 76 requests / second Real-world: as routing table gets longer and more parameters get passed around, the difference is even greater!
  • 52. We can cache site statistics. Here’s our little caching API that uses lambda syntax for cached values. A lot less code!
  • 53. Cache stats and top voted news of all time: 76 requests/ second => 153 requests/ second. Let’s also cache the main news display: 153 requests/ second => 400 requests / second. Caching all DB data foregoes any SQL-LINQ or SQL connection initialization. Even less overhead with much faster response times.
  • 54. Core2 Duo 2.53GHz, 4GB RAM, IIS7 Optimization only Data caching 450 400 Requests per second 400 350 300 250 200 153 150 76 61.5 100 52 27 25.5 50 8 0
  • 55. Each of these optimization methods is in production: fast URL generation, compiled queries, URL caching, data caching. The first alpha version without any optimizations ran at ~3 requests / second. Today, the index page can withstand ~800 requests/second on a development webserver with real world DB data. HTTP concurrency = 8.
  • 56. After a few uncomfortable moments of silence... Questions?
  • 57. Ideas for ASP.NET MVC developers:   Smarter view compiling. Let’s inline partial code for views. Or let’s write a new view engine.  RenderPartials() method that accepts an enumeration and can also use a spacer view – like RoR.  Builtin URL caching – why not? Or at least make interfaces for HTML and URL helpers.
  • 58. Thanks to Simone Chiaretta for discovering a gross oversight on my part: I’ve done my benchmarks with ASP’s debug mode turned on. With regards to ASP.NET MVC 1.0, this disables its view engine’s internal cache for resolved paths to views. This makes specifying full paths to view irrelevant as far as performance is considered. So, the following change won’t yield any performance yield with the debug attribute set to false (Web.config, compilation section).
  • 59. All of the benchmarks have been re-run with debug turned off, the change before any optimizations have taken place is significant (6 req/s to 8 req/s). Any other changes to the performance due to the release mode other than view path resolving were basically non- existing or within the margin of error. You can read Simone’s post at http://codeclimber.net.nz/archive/2009/04/22/how-to-improve- htmlhelper.renderpartial-performances-donrsquot-run-in-debug-mode.aspx And, of course, run your production websites in release mode. :)