SQL in the City, London, 2014: How to speed up .NET and SQL Server web apps

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

Transcript of SQL in the City, London, 2014: How to speed up .NET and SQL Server web apps

How to speed up .NET and SQL Server web

appsBart Read

Who am I?• Bart Read, Consultant, Software Engineer• .NET, SQL Server, performance tuning, project management

• 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

Tools of the Trade

.NET Performance & Memory Profilers

SSMS & SQL Profiler

Load Testing

SQL Server Monitoring Tools

Useful Ancillary Tools

Scenario 1The Slow Support Centre

Customer Support Centre

(MS Dynamics)

Scenario 2The Memory Leak in the eCommerce Site

eCommerce Site

(MS Dynamics)

Other technologies:- NServiceBus- Endeca

Solution (Nasty Hack)

container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();

(Creating some technical debt for the future.)

Scenario 3Locking, Blocking and Deadlocking

Locking, Blocking & Deadlocking

Concurrency• Object level concurrency• Row level concurrency

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

ACID

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.

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

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

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