SQL Server Baselining, Benchmarking and Workload Analysis Gianluca Sartori sqlconsulting.it
Gianluca Sartori Independent SQL Server consultant SQL Server MVP, MCTS, MCITP, MCT Works with SQL Server since version 7 DBA @ Scuderia Ferrari Blog: spaghettidba.com Twitter: @spaghettidba
AGENDA Baselining Workload Analysis Benchmarking What happens in “normal” conditions? Workload Analysis How are applications and databases interacting with each other? Benchmarking What if…?
Health Check Why? When? How? Improve performance Improve manageability Regularly Assessment Continuously Monitoring How? A methodology is needed
Health Check
Baselining Let’s establish what’s normal 9/10/2018 6:34 PM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
What is a baseline? Describes system performance in «normal» conditions Used a comparison basis Monitoring Troubleshooting Trend Analysis and Capacity Planning
Creating a baseline What to capture? How to capture? How often? Where to store the captured data? How long to keep it? How to analyze it?
What to capture? General information System SQL Server Version HW (CPU, RAM, disk…) SQL Server Version and edition Configuration options Database inventory File size and placement
What to capture? Performance indicators Wait Stats Performance Counters Dynamic Management Objects Query Stats
Wait Stats DMV sys.dm_os_wait_stats Tracks time spent by processes in a wait queue Wait times are cumulative (since last server restart) Great starting point for troubleshooting Allows to identify problems from their symptoms Shows which areas need attention Not all wait classes are meaningful!
Wait Stats Common wait classes Resource Class Example Locking LCK_* LCK_M_S LCK_M_X Latching LATCH_* PAGELATCH_* LATCH_EX PAGELATCH_UP I/O PAGEIOLATCH_* *_COMPLETION WRITELOG PAGEIOLATCH_SH IO_COMPLETION ASYNC_IO_COMPLETION CPU THREADPOOL SOS_SCHEDULER_YIELD Network ASYNC_NETWORK_IO Parallelism CXPACKET
Demo WAIT STATS
Performance Counters Which counters? CPU Memory Disk SQL – specific … More than 400 in SQL Server 2016!!!
DMO sys.dm_os_ OS information sys.dm_io_ Disk performance sys.dm_exec_ Sessions, requests, connections sys.dm_db_ Database info sys.dm_tran_ Transactions, locks sys.dm_... Audits, broker, CDC, FileStream, FTS, HADR, Repl, RG, XE… Not all DMOs are performance related
Which DMOs? 141 DMOs in SQL Server 2016!!! SELECT name ,type_desc Periodic Table of SQL Server Dynamic Management Objects 141 DMOs in SQL Server 2016!!! SELECT name ,type_desc FROM sys.all_objects WHERE name LIKE 'dm[_]%' ORDER BY name http://thesqlagentman.com/periodic-table/
What to capture? How do you work with 400 performance counters and 141 DMOs? Glenn Berry’s Diagnostic Information Queries http://www.sqlskills.com/blogs/glenn/category/dmv-queries/ Davide Mauri’s SYS2 DMVs http://sys2dmvs.codeplex.com/ Brent Ozar’s sp_Blitz http://www.brentozar.com/blitz/ Kendall van Dyke’s SQLPowerDoc https://sqlpowerdoc.codeplex.com/
Performance Data Collector Available in all editions (except Express) Contains System Collection Sets Extensible model, custom Collection Sets Extended T-SQL Collector http://extendedtsqlcollector.codeplex.com Captures data at regular intervals Data saved in a Management Datawarehouse Multiple instances can share the same MDW May be integrated with Utility Control Point Comes with reports to read and analyze the data Reports can be centralized on Reporting Services: http://blogs.msdn.com/b/billramo/archive/tags/mdw+reports/
How long to keep the data? It depends on Available disk space Depth of analysis required Volatility of the environment
Which data participate the baseline? Select a subset of the data captured for monitoring Select baseline regularly “Implicit” selection previous day/week/month “Explicit” selection extract a snapshot Only one baseline? Depends on business cycle Depends on applications
Business Cycle
Monitoring Baseline Compare the instant value of the performance metric with its baseline Baseline must be chosen keeping the business cycle in mind
Workload Analysis What drives the load on SQL Server? 9/10/2018 6:34 PM Workload Analysis What drives the load on SQL Server? © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Workload Analysis Performance effect Workload cause Workload analysis allows to correlate cause and effect Outcome of analysis is a plan
Query Statistics DMV sys.dm_exec_query_stats Information on all queries in plan cache Rank queries in terms of: IO Reads Writes CPU Execution count
Plan cache analysis Correlate wait stats and query stats Identify problematic queries Missing indexes Implicit conversions Identify application issues “Plan cache bloat” Since 2012, DTA can use plan cache as a source
Query Store New in SQL Server 2016 Data is persisted throughout restarts Allows to find plan regressions Allows “fixing” rogue plans with no effort
Demo PLAN CACHE ANALYSIS
Trace Often query stats are not enough What to capture with traces? Volatile Don’t capture queries marked as RECOMPILE What to capture with traces? Events Columns Filters Collection tools Profiler vs. SQLTrace
Extended Events Introduced in SQL Server 2008 (eg: Audit) Expose events deep inside SQLOS Often not available otherwise Lightweight Configurable Replacement for SQL Trace (since 2012) Used to lack some features Analysis tools Replay tools Now 100% covered
Workload Analysis What to analyze Analysis tools Depends on what you captured Correlate with performance counters Analysis tools RML Utilities (ReadTrace) Watch out for trace file version http://bit.ly/1T9vJwV conversion PSSDIAG SQL Nexus ClearTrace
Demo CLEARTRACE
Benchmarking Imagine new scenarios… 9/10/2018 6:34 PM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
What is a benchmark? Describes performance in different scenarios Evaluates whatif scenarios: Hardware/Software Upgrade Virtualization Helps rating tuning efforts Server-wide configuration changes Addition/removal of indexes Code changes
Performance benchmarking
Workload capture Which tool? Which events should you capture? SQL Trace vs. Profiler Prefer SQL Trace Which events should you capture? Which columns should you capture? RML Utilities Trace definition script Backup the database First issue a full backup, then start the trace First run the trace, then issue a full backup Filter the trace
Workload replay Prepare the test environment Must be a complete clone Restore User Databases Keep original database_id! Logins Watch out for orphaned users! Jobs SSIS Packages Database Mail Test environment must be isolated from production!
Workload replay Which tool? Profiler RML Utilities - Ostress Distributed Replay Introduced in SQL Server 2012 Can replay a workload form multiple clients Same query rate of the original trace (synchronization mode)
Distributed replay 3 core elements: Administration tool Distributed Replay Controller Distributed Replay Client
Workload replay Which tool?
Baseline Capture Reset performance metrics DBCC SQLPERF("sys.dm_os_wait_stats",CLEAR); DBCC FREEPROCCACHE(); DBCC FREESYSTEMCACHE('ALL'); DBCC DROPCLEANBUFFERS(); Take a snapshot for each database Start collection Performance Monitor Collection Set SQLTrace – RML Template
Benchmark Capture Revert to snapshot Apply changes Start collection of performance metrics Start replay
Benchmark Analysis Analysis = compare with Baseline Analysis tools: RML Utilities https://support.microsoft.com/en-us/kb/944837 SQLNexus http://sqlnexus.codeplex.com/ ClearTrace http://www.scalesql.com/cleartrace/default.aspx Qure Analyzer http://www.dbsophic.com/qure-analyzer
Demo QURE ANALYZER
Questions & Answers 9/10/2018 6:34 PM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Izpolnite anketo! Vam je bilo predavanje všeč? Ste se naučili kaj novega? Vaše mnenje nam veliko pomeni! Da bo NT konferenca prihodnje leto še boljša, vas prosimo, da izpolnite anketo o zadovoljstvu, ki jo najdete v svojem NTK spletnem profilu.
9/10/2018 6:34 PM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.