DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

61
How to speed up .NET and SQL Server web apps Bart Read

Transcript of DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Page 1: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

How to speed up .NET and SQL Server web

appsBart Read

Page 2: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Who am I?• Bart Read, Web, Database, and Mobile Performance Consultant• Previously worked for Red Gate• Contacts• E: [email protected]• W: www.bartread.com• B: www.bartread.com/blog• T: @bart_read• GH: https://github.com/bartread

Page 4: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Always measure! (But

it’s almost never the

code!)

Page 5: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Production Monitoring

Page 6: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Detailed Diagnostic Tools

Page 7: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Other Handy Ancillary Tools

Page 8: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

A word of warning about SSMS

Read Erland Sommarskog’s post, “Slow in the application, fast in SSMS?”: http://www.sommarskog.se/query-plan-mysteries.html

Page 9: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Scenario 1The Slow Support Centre

Page 10: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Customer Support Centre

(MS Dynamics)

Page 11: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 12: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 13: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 14: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 15: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 16: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 17: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 18: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 19: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 20: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 21: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 22: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 23: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 24: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 25: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 26: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 27: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 28: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Grant Fritchey’s FREE eBook on execution plans:

http://www.red-gate.com/community/books/sql-server-execution-plans-ed-2

Tool: http://www.supratimas.com/

Page 29: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 30: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 31: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 32: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Scenario 2The Memory Leak in the eCommerce Site

Page 33: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

eCommerce Site

(MS Dynamics)

Other technologies:- NServiceBus- Endeca

Page 34: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 35: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 36: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 37: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 38: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 39: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 40: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Scenario 3Locking, Blocking and Deadlocking

Page 41: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Locking, Blocking & Deadlocking

Page 42: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 43: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Concurrency• Object level concurrency• Row level concurrency

Page 44: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 45: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Transaction Isolation Levels• Read Uncommitted• Read Committed <- SQL Server default• Repeatable Read• Snapshot• Serializable

ACID

Page 46: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 47: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 48: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

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.

Page 49: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Solutions• DEADLOCK_PRIORITY• http://msdn.microsoft.com/en-us/library/ms186736.aspx• SET DEADLOCK_PRIORITY LOW | NORMAL | HIGH

• Read Committed Snapshot Isolation• http://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-

committed-snapshot-isolation-in-sql-server-a-guide/

• Disciplined ordering of object access• Unit of Work Pattern

• Martin Fowler• http://martinfowler.com/eaaCatalog/unitOfWork.html

Page 50: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Scenario 4Networking

Stuart Cheshire, “It’s the latency, stupid” (1996): http://www.stuartcheshire.org/rants/latency.html

Page 51: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Fast/Slow Query

Page 52: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 53: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 54: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)
Page 55: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Query Frame

Page 56: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Result Set Frame

Page 57: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Virtual NIC Setting To Blame

Page 58: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Client-side Scenarios - General Observations• Payload• Chattiness/latency• CSS transitions and animations• Code execution time again becomes an issue• Garbage• High memory usage

Page 59: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Star Citadel: https://arcade.ly/games/starcastle

Page 60: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Other Scenarios• Indexes• Missing indexes• Maintenance• Statistics• NTEXT (etc.) preventing online rebuilds

• http://www.bartread.com/2014/09/17/convert-all-ntext-columns-to-nvarcharmax-sql-server/

• Stored procedures and cached execution plans• WITH RECOMPILE

Page 61: DDD 2016: How to speed up .NET and SQL Server web apps (Reading, UK)

Questions?E: [email protected]: www.bartread.comB: www.bartread.com/blogT: @bart_readGH: https://github.com/bartread

Red Gate coding challenge: http://www.red-gate.com/our-company/entrypage/coding-challenge