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.

Extended edition: How to speed up .NET and SQL Server web apps (2 x 45 mins with break)


Published on

This talk describes the tools and techniques I use to diagnose performance problems in .NET and SQL Server web apps. The talk is based on a series of real world examples that allow you to build a picture of the sort of outside-in approach that works well for figuring out performance bottlenecks.

Often, once you've isolated the problem, the fix is fairly simple. Where I tend to find people struggle is in isolating problems in the first place so my aim here is to equip you to understand why your app is performing poorly.

Increasingly applications are becoming more complex with dependencies not just on the database (or several databases), but often other services. Infrastructure, networking, storage, and the client also increasingly have an impact nowadays, and this is something I try to emphasise throughout, giving you an overview of which tools to use in each case.

This is a longer version of the talk than I usually give so I take advantage of the extra time available to discuss an issue that many developers struggle with: memory management. Normally I have to skim over this but in this case I've gone into some depth about how memory is managed in runtimes such as the .NET CLR, the JVM, and JavaScript works. This will help you write code that works with the garbage collector rather than against it.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Extended edition: How to speed up .NET and SQL Server web apps (2 x 45 mins with break)

  1. 1. How to speed up .NET and SQL Server web apps Bart Read
  2. 2. Who am I? • Bart Read, Web, Database, and Mobile Performance Consultant • Previously worked for Red Gate • Contacts • E: • W: • B: • T: @bart_read • GH:
  3. 3. General Web Performance 014/06/03/web- performance-how-fast-does- website-need-to-be/
  4. 4. Always measure! (But it’s almost never the code!) But see Matt Warren, Performance is a feature,
  5. 5. Production Monitoring
  6. 6. Detailed Diagnostic Tools
  7. 7. Other Handy Ancillary Tools
  8. 8. A word of warning about SSMS Read Erland Sommarskog’s post, “Slow in the application, fast in SSMS?”:
  9. 9. Scenario 1 The Slow Support Centre
  10. 10. Customer Support Centre (MS Dynamics)
  11. 11. Grant Fritchey’s FREE eBook on execution plans: ql-server-execution-plans-ed-2 Tool:
  12. 12. Scenario 2 The Memory Leak in the eCommerce Site
  13. 13. GC Overview: The Mark and Sweep Algorithm (Used by .NET, Mono, Java Virtual Machine, and JavaScript runtime implementations)
  14. 14. The Lifecycle of a Typical Object 1. Allocate memory 2. Initialize memory 3. Use object 4. Tear down (Dispose/Close/finalize) [mostly not required] 5. Free memory
  15. 15. Assumptions 1. Objects have very short lifetimes, otherwise 2. Objects that don’t have very short lifetimes have very long lifetimes
  16. 16. eCommerce Site (MS Dynamics) Other technologies: - NServiceBus - Endeca
  17. 17. Scenario 3 Locking, Blocking and Deadlocking
  18. 18. Locking, Blocking & Deadlocking
  19. 19. Concurrency • Object level concurrency • Row level concurrency
  20. 20. Transaction Isolation Levels • Read Uncommitted • Read Committed <- SQL Server default • Repeatable Read • Snapshot • Serializable ACID
  21. 21. Locking pattern • Reads • A -> B -> C -> D -> A -> B -> C -> D -> E -> A … • Etc. • Writes • A –> B -> C -> D -> E -> A -> B -> A -> B -> C -> D … • Etc.
  22. 22. Solutions • DEADLOCK_PRIORITY • • SET DEADLOCK_PRIORITY LOW | NORMAL | HIGH • Read Committed Snapshot Isolation • read-committed-snapshot-isolation-in-sql-server-a-guide/ • Disciplined ordering of object access • Unit of Work Pattern • Martin Fowler •
  23. 23. Scenario 4 Networking Stuart Cheshire, “It’s the latency, stupid” (1996):
  24. 24. Fast/Slow Query
  25. 25. Query Frame
  26. 26. Result Set Frame
  27. 27. Virtual NIC Setting To Blame
  28. 28. Scenario 5 In which we show that sometimes it actually is the code
  29. 29. Solutions • Both these queries take 10 – 20ms to execute: • SELECT DISTINCT PropertyReferenceID FROM PropertyDedupe WHERE PropertyID = {0} • SELECT TOP 1 PropertyReferenceID FROM PropertyDedupe WHERE PropertyID = {0} • Move cache building to a background thread, and don’t ever let GetCache(…) return null (or an unpopulate or partially populated cache).
  30. 30. Client-side Scenarios - General Observations • Payload • Chattiness/latency • CSS transitions and animations • Code execution time again becomes an issue • Garbage • High memory usage
  31. 31. Star Citadel:
  32. 32. Other Scenarios • Indexes • Missing indexes • Maintenance • Statistics • NTEXT (etc.) preventing online rebuilds • server/ • Stored procedures and cached execution plans • WITH RECOMPILE
  33. 33. Questions? E: W: B: T: @bart_read GH: Red Gate coding challenge: