SQL Server Performance Tuning Baseline

2,590 views

Published on

An Overview of SQL Server Performance Tuning Baseline Setup

Published in: Technology
2 Comments
9 Likes
Statistics
Notes
No Downloads
Views
Total views
2,590
On SlideShare
0
From Embeds
0
Number of Embeds
75
Actions
Shares
0
Downloads
7
Comments
2
Likes
9
Embeds 0
No embeds

No notes for slide

SQL Server Performance Tuning Baseline

  1. 1. 1GE Title or job number 8/15/2012
  2. 2. I. Performance Monitoring OverviewII. Monitoring Database ServersIII. Using SQL ProfilerIV. Using the Database Engine Tuning AdvisorV. Application Design TipsVI. Managing Processes, Locking, and Deadlocks 2 GE Title or job number 8/15/2012
  3. 3. 3GE Title or job number 8/15/2012
  4. 4. Best Practices: Establish a baseline  Optimize for real- world workloads Repeat Identify(if desired) bottlenecks  Monitor/review performance regularly Measure Make one  Focus on specific performance change at a time issues 4 GE Title or job number 8/15/2012
  5. 5. System/OS SQL Server Query-Level Activity MonitorWindows Performance Database Engine Monitor Tuning Advisor SQL Profiler / SQL Trace Database Engine Tuning AdvisorAlerts (Performance- Based) Query Execution Plans Dynamic Management Views (DMVs) 5 GE Title or job number 8/15/2012
  6. 6. • Users are reporting database timeoutsServer-Level • Intermittent transaction timeouts Issues • “The server/application seem sluggish”Application- • “Application A is running more slowly Specific than usual” Issues • “The End-of-Month report is taking too long to run.” • Ad-hoc reports are running slowlyOther Issues • CPU, memory, disk, or network alerts are being generated 6 GE Title or job number 8/15/2012
  7. 7. Available in all current versions of WindowsStatistics are organized into: Objects Counters InstancesData Collector Sets Windows Vista / Windows 7 / Windows Server 2008 Used to report on performance data that is collected over time Includes built-in System Diagnostics and System Performance collectors and reports 8 GE Title or job number 8/15/2012
  8. 8. Backup Device General Statistics Device throughput Bytes/sec  Logins | logouts / secBuffer Manager  User Connections Buffer cache hit ratio Latches Page reads / sec  Latch waits / secBuffer Partition Locks Free Pages  Lock requests / sec  Lock waits / secCache Manager Memory Manager Cache Hit Ratio  Everything!Databases Replication Active Transactions  Depends on configuration Data File Size Log Growths SQL Statistics Percent Log Used  Batch requests / sec Transactions / sec  SQL compilations / sec 9 GE Title or job number 8/15/2012
  9. 9. SQL Server Activity MonitorProvides a quick overview of database server activityCPU, Processes, Resource Waits and Disk I/O“Recent Expensive Queries”SQL Server Management Studio ReportsQuick overview of SQL Server usageCan export to Excel or PDF 10 GE Title or job number 8/15/2012
  10. 10. Server Dashboard Disk UsageMemory Consumption All TransactionsActivity – All Block Transactions All Blocking TransactionsActivity – Top Sessions Index Usage StatisticsPerformance – Batch Execution Top Transactions by Age Statistics Schema Changes HistoryPerformance – Top Queries by Average CPUObject Execution Statistics Database-Level Reports 11 GE Title or job number 8/15/2012
  11. 11. Windows Event Logs / Event Viewer Application and System Event LogsSQL Server Management Studio SQL Server Logs  Can configure max. # of log files SQL Server Agent Error logs  Can configure logging levels (Errors, Warnings, Information)Using the Log File Viewer Can Export / Load log information Can search for specific errors/messages 12 GE Title or job number 8/15/2012
  12. 12. Purpose: Monitoring and troubleshooting View server state and performance details Returns relational result sets (use standard SELECT statements)Full list can be viewed in “Views  System Views” section of the properties of the databaseScopes: Server level Database level 13 GE Title or job number 8/15/2012
  13. 13. Query Execution / Processes •sys.dm_exec_requests Storage Engine sys.DM_DB_File_Space_Usage Indexessys.DM_DB_Index_Operational_Statssys.DM_DB_Index_Physical_Stats Disk I/O sys.DM_IO_Pending_IO_Requests sys.DM_IO_Virtual_File_Stats Other CategoriesSchema information | Common Language Runtime (CLR)Database Mirror / Clustering | Replication 14 GE Title or job number 8/15/2012
  14. 14. Data Collected: System Information (MSINFO) Windows Event Logs SQL Server configurationCommand-Line Utility (SQLDiag.exe) Stores output to files Configuration file: SQLDiag.xml Can run as a service (/R) Can run in continuous mode 15 GE Title or job number 8/15/2012
  15. 15. Purpose / Features: GUI for managing SQL Trace Monitor important events Capture performance data / resource usage Replaying of workloads / transactions Identifying performance bottlenecks Correlation of data with System Monitor Workloads for Database Tuning AdvisorExamples: Generate a list of the 100 slowest queries Monitor all failed logins (Security) 17 GE Title or job number 8/15/2012
  16. 16. SQL Profiler Terminology Trace Definitions Events Columns FiltersCreating and Managing SQL Traces SQL Profiler (GUI) System Stored Procedures (Transact-SQL)Trace Templates (Built-In) Standard (Default), SP_Counts TSQL, TSQL_Duration, TSQL_Grouped,TSQL_Replay, TSQL_SPs Tuning 18 GE Title or job number 8/15/2012
  17. 17. Trace A set of events, data columns and filters that specify what data should be collected Data can be saved to a file or a database tableTrace File Trace data that is saved to a binary file Default extension is “.trc”Trace Table A SQL Server database table in which trace information is stored Profiler will automatically create the structure of this table when you start running a new traceTrace Template Saved specifications that can be used as the basis for new traces E.g., an environment may have a “Security Monitoring template”, a “CRM Application Performance”, etc. Default extension is “.tdf” 19 GE Title or job number 8/15/2012
  18. 18. Groupings: Event Event Categories Categories Event Classes EventsExamples: Event Classes TSQL Stored Procedures Performance Errors and Warnings Security auditing Events 20 GE Title or job number 8/15/2012
  19. 19. Specifies the details to be monitored/recordedConfiguring columns Columns can be ordered and grouped Values can be filteredExamples of Columns: StartTime / EndTime TextData Duration Resource Usage (CPU, Reads, Writes) Information: User, Database, App. Names 21 GE Title or job number 8/15/2012
  20. 20. Interactive Good for “live” monitoring of small sets of dataTrace Files (*.trc) Can enable file rollover based on size “Server processes trace data” optionTrace table Will automatically create the table Can set maximum number of rowsScheduling of traces (stop time) 22 GE Title or job number 8/15/2012
  21. 21.  Launching SQL Profiler Connecting to a database instance Configuring output options Create a trace definition Specifying events, columns, and filters Running and viewing a trace 23 GE Title or job number 8/15/2012
  22. 22. Creating new templates using SQL ProfilerScripting trace definitions sp_trace_create sp_trace_setfilter sp_trace_GenerateEvent sp_trace_SetEvent sp_trace_SetStatusExtracting SQL Server Events Transact-SQL Events ShowPlan Events Deadlock Events 24 GE Title or job number 8/15/2012
  23. 23. Purpose / Goal: Correlate server performance with database performanceProcess: Define and start a counter log Define and start a SQL Profiler trace Import Performance Data in SQL ProfilerRequired Trace properties StartTime EndTime 25 GE Title or job number 8/15/2012
  24. 24. Reviews sample workloads and makes performance recommendationsEvaluates Physical Design Structures (PDS) Indexes (clustered, non-clustered) Indexed Views PartitionsNumerous analysis optionsOutput Generates modification scripts Generates Reports for later analysis 27 GE Title or job number 8/15/2012
  25. 25. Files Transact-SQL Files XML Files Should represent commonly-used queriesSQL Profiler Trace Files / Tables Use Tuning built-in trace template Events:  Transact-SQL Batch  Remote Procedure Call (RPC) Columns: Event Class and Text Data 28 GE Title or job number 8/15/2012
  26. 26. Limit tuning timeTuning Options Allowed Physical Design Structures (PDS) Keep all/specific existing objects Maximum storage space Online or offline recommendations Partitioning 29 GE Title or job number 8/15/2012
  27. 27. Reports can be exported to XML filesReport Examples: Workload View-Table Column access Table access analysis Relations Index Usage Statement cost Event frequency (current / recommended) 30 GE Title or job number 8/15/2012
  28. 28. Process: Generate a workload (file or table) Select tuning options Run the analysis View reports Save and/or apply recommendationsRunning the DTA: Database Engine Tuning Advisor Application (GUI) DTA.exe command-line utility 31 GE Title or job number 8/15/2012
  29. 29. Create an abstraction layer between the database and the presentation code Separates presentation and logic (esp. in Web Apps) Example: ADO.NET DatasetsDatabase design: Understand typical use-cases before designing the database Create and enforce naming conventions Balance write (OLTP) and read (reporting) performance requirements Use strategic denormalization 33 GE Title or job number 8/15/2012
  30. 30. Never include actions that require user input within a transactionUse connection pooling, whenever possible Open connections late and close them early Avoid unnecessary server round-tripsUse client-side caching whenever possible Optimistic concurrency Pessimistic concurrencyDistribute processing Some operations are more efficient on the DB server (e.g., aggregations, sorting, etc.) 34 GE Title or job number 8/15/2012
  31. 31. Processes Interactive users  SQL Server Management Studio Applications (Connection Pooling)  SQL Profiler  Database Engine Tuning Advisor  Replication  Service BrokerProcess IDs < 50 are system-related 36 GE Title or job number 8/15/2012
  32. 32. SQL Server Activity Monitor Processes (connected users) Locks (by Process / by Object) Filtering options Auto-refresh optionSystem Stored Procedures / Views Sys.DM_Exec_Sessions Sys.DM_Exec_Requests Sys.SysProcesses sp_who / sp_who2 37 GE Title or job number 8/15/2012
  33. 33. Process Information Current Process ID: @@SPID Session Options: DBCC USEROPTIONSKilling Processes KILL ProcessID [WITH STATUSONLY]Viewing Last Activity DBCC INPUTBUFFER(ProcessID) DBCC OUTPUTBUFFER(ProcessID) 38 GE Title or job number 8/15/2012
  34. 34. Coordinates multiple accesses to the same dataEnsures ACID Properties for transactions (Atomic, Consistent, Independent, Durable)Contention can reduce performanceLocking granularity: Row-Level, Page-Level, Table-Level, etc.Lock Modes: Shared, Exclusive, etc.Lock escalation 39 GE Title or job number 8/15/2012
  35. 35. Blocking When transaction(s) must wait for a lock on a resource LOCK_TIMEOUT setting (default = wait forever)Locking Models: Pessimistic Optimistic 40 GE Title or job number 8/15/2012
  36. 36. Balance of concurrency (performance) vs. consistency Affects SELECT queries SET TRANSACTION ISOLATION LEVELTransaction Isolation Levels READ UNCOMMITTED READ COMMITTED (default) REPEATABLE READ SERIALIZABLE SNAPSHOTRow-Versioning: ALLOW_SNAPSHOT_ISOLATION READ_COMMITTED_SNAPSHOT 41 GE Title or job number 8/15/2012
  37. 37. Activity MonitorSQL Profiler Locks Event CategorySystem Monitor: SQL Server  Locks ObjectSystem Views Sys.DM_Tran_Locks Sys.DM_Exec_RequestsSystem Stored Procedures sp_Lock 42 GE Title or job number 8/15/2012
  38. 38. Deadlocks: Two or more tasks permanently block each other based on resource locks Default resolution is within 5 secondsDeadlock victim Transaction is rolled-back Process receives a 1205 errorExample: Process 1 locks the Customers table and requires access to the Orders Table Process 2 locks the Orders table and requires access to the Customers Table 43 GE Title or job number 8/15/2012
  39. 39. Minimize transaction times Commit / Rollback transactions as quickly as possibly Avoid user-related time within a transactionAccess objects in a consistent orderChange the transaction isolation level Use a lower level isolation level, if appropriate Use snapshot-based isolation levels 44 GE Title or job number 8/15/2012
  40. 40. Deadlock priorities: SET DEADLOCK_PRIORITY (LOW, NORMAL, HIGH, integer)Deadlock resolution: Lower priority is killed first If equal priorities, least expensive transaction becomes the victim Application or user should attempt to re-run the transaction 45 GE Title or job number 8/15/2012
  41. 41. SQL Server Error LogSQL Profiler Locks Event Category  Lock: Deadlock Chain  Lock: Deadlock  Deadlock Graph Events Extraction Trace Property Export deadlock XML (.xdl) fileViewing Deadlock Files SQL Server Management Studio (File  Open  SQL Deadlock Files (*.xdl) 46 GE Title or job number 8/15/2012
  42. 42. 47GE Title or job number 8/15/2012

×