Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Improving ASP.NET MVC Application Performance


Published on

You've built an ASP.NET MVC application, but now you want it to go faster and serve more concurrent user requests. In this session, we'll look at some of the common performance problems ASP.NET MVC applications may encounter, and how to diagnose and correct them, using Visual Studio 2010's testing tools.

Presented 8 Feb 2010 at

Published in: Technology
  • Njce! Thanks for sharing.
    Are you sure you want to  Yes  No
    Your message goes here
  • If you are looking to do some additional performance tuning, there are a lot of different tools to help you find and optimize ASP.NET performance. I made a great list of 9 different types of tools. Check it out and see if any of these can help: ASP.NET Performance: 9 Types of Tools You Need to Know!
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi Steven

    Great presentation, thanks

    We've also had issues with slow performance with some MVC apps, so I put together a complete list with code examples.

    Please take a look and let me know what you think:

    Are you sure you want to  Yes  No
    Your message goes here
  • Well presented! Here I’d add one more point that app performance can be enhanced by caching. Caching is incredible tool for performance enhancement and if scalability is also a concern then distributed caching is perfect technique. Any third party Distributed Cache (Like NCache) can be used.
    Are you sure you want to  Yes  No
    Your message goes here

Improving ASP.NET MVC Application Performance

  1. 1. Improving ASP.NET MVC Application Performance Steve Smith The Code Project |
  2. 2. Defining Performance Metrics• Page Execution Time• Requests/Sec• TTLB
  3. 3. Defining Performance Requirements• A given web request (/Home/Index)• Must return within a given time (TTLB or Page Execution Time)• Under a given load (Requests/Sec + Active Users)• Given system characteristics (50k records)• Resource constraints (< 400 database server requests/sec)
  4. 4. Performance Requirement• /Home/Index• Must return within 1s Page Execution Time• Given 100 request/sec and base database• With < 200 database requests/sec
  5. 5. Measure Baseline• Record the Scenario• Set up the Load Test• Run the Test• Analyze the Results
  6. 6. Baseline Measurement: MVC Music
  7. 7.
  8. 8. Find the Slowest
  9. 9. Tuning a Web Application Define Goal Meets Goal Measure System Stop Does Not Meet Goal Form Hypothesis; Change Only One Thing! Alter
  10. 10. Most Common Performance Problems• Database – Too many queries – Queries Not Optimized• Network Requests – From Server to Services – From Browser to Web Server
  11. 11. Simple but Important• Be sure production DLLs are compiled in Release mode!• (still alpha)
  12. 12. Caching• Output Caching – [OutputCache] attribute – Applies to • Action methods within Controller • Or Entire Controller
  13. 13. Identify Pages To
  14. 14. Applying Output
  15. 15.
  16. 16. Add Data Caching• Apply to Read operations• Use where Output Caching can’t be used• Consider applying at Repository level• Consider using Sql Cache Invalidation or short cache duration
  17. 17. What About Writes?• Avoid blocking on writes – Send messages – Use Async calls on server – Use Async/Ajax calls from client• Logically partition reads and writes – Command Query Responsibility Separation (CQRS)
  18. 18. Other Tools:
  19. 19. Tier
  20. 20. What about Async?• Async Actions• AsyncController• Improves scalability• May improve performance
  21. 21. Comparing MVC and View Engines• MVC 2 Template on MVC 2 – 8135 Requests/sec• MVC 2 Template on MVC 3 – 7987 Requests/sec• MVC 3 Webforms View Engine on MVC 3 – 7457 Requests/sec• MVC 3 Razor View Engine on MVC 3 – 7136 Requests/sec
  22. 22. MVC 3 Performance• Unobtrusive client-side validation on by default• Razor view engine imposes small cost over webforms view engine• Performance improved for: – Expression caching (lambdas) – URL generation – Action lookup – Filter invocation
  23. 23. MVC Gotchas• Avoid HttpResponse.WriteSubstitution() – Contents may be incorrectly cached – – May work with MVC3 + ASPX; not supported; definitely not w/Razor• RenderAction() Cache Bug – Calling an action with OutputCache attribute may result in entire page being cached –
  24. 24. MVC Performance TipsDisable Unused View Engines• Html.EditorFor, Html.DisplayFor always look for templates for each view engine• Save extra “misses” to disk by removing unused view engines.
  25. 25. Remove Unused View
  26. 26. MVC Performance TipsAvoid Passing Null to Strongly Typed Views w/Helpers• Helpers like Html.TextBoxFor(m => m.Name) will throw NullReferenceException• Exceptions will be caught/ignored, but may add up to negative performance impact
  27. 27. Avoid Passing Null to
  28. 28. MVC Performance TipsUninstall IIS UrlRewrite Module• If no applications on the server are using it• No effect in MVC apps before v3• Enhances speed of URL generation
  29. 29. Uninstall UrlRewrite (if not used)
  30. 30. Applying Performance
  31. 31. Summary of Perf Gains300250200 Base Release Mode150 No Null ViewModel100 1 ViewEngine 50 OutputCache 0 Pages/Sec Page Time (ms)
  32. 32. Summary• Set Goals – Don’t Optimize Prematurely• Measure and Tune Scientifically• Look for big wins first• Watch out for Gotchas and apply Tips
  33. 33. References••••••
  34. 34. Questions?Tweet Your Questions to:@ardalis How do I…? #mvcconfSteve Smithssmith@lakequincy.comSteveSmithBlog.comTwitter: @ardalis