Seminar 5. MS SQL Server - Performance Tuning -



Similar documents
Performance Monitoring with Dynamic Management Views

Solving Performance Problems In SQL Server by Michal Tinthofer

Analyzing & Optimizing T-SQL Query Performance Part1: using SET and DBCC. Kevin Kline Senior Product Architect for SQL Server Quest Software

Performance Counters. Microsoft SQL. Technical Data Sheet. Overview:

PERFORMANCE TUNING IN MICROSOFT SQL SERVER DBMS

Introduction. Part I: Finding Bottlenecks when Something s Wrong. Chapter 1: Performance Tuning 3

MS SQL Performance (Tuning) Best Practices:

About Me: Brent Ozar. Perfmon and Profiler 101

DBMS Performance Monitoring

VirtualCenter Database Performance for Microsoft SQL Server 2005 VirtualCenter 2.5

SQL Server 2012 Query. Performance Tuning. Grant Fritchey. Apress*

Microsoft SQL Server performance tuning for Microsoft Dynamics NAV

Guerrilla Warfare? Guerrilla Tactics - Performance Testing MS SQL Server Applications

Improving SQL Server Performance

SQL Server Query Tuning

Microsoft SQL Server: MS Performance Tuning and Optimization Digital

SQL Server Performance Tuning and Optimization

SQL Server 2012 Optimization, Performance Tuning and Troubleshooting

EZManage V4.0 Release Notes. Document revision 1.08 ( )

SQL Server Performance Tuning and Optimization. Plamen Ratchev Tangra, Inc.

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Execution Plans: The Secret to Query Tuning Success. MagicPASS January 2015

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

Performance Tuning and Optimizing SQL Databases 2016

The Complete Performance Solution for Microsoft SQL Server

Database Monitoring and Performance Tuning

Oracle Database 11g: SQL Tuning Workshop

Oracle Database 11g: SQL Tuning Workshop Release 2

Response Time Analysis

Chapter 15: AppInsight for SQL

CHAPTER 8: OPTIMIZATION AND TROUBLESHOOTING

Query Performance Tuning: Start to Finish. Grant Fritchey

Waiting and Blocking Issues

Optimizing Performance. Training Division New Delhi

Mind Q Systems Private Limited

There are four technologies or components in the database system that affect database performance:

SQL Server Performance Tuning Using Wait Statistics: A Beginner s Guide. By Jonathan Kehayias and Erin Stellato

DBMS / Business Intelligence, SQL Server

Module 15: Monitoring

MS SQL Server 2005 Data Collector. Status: 12/5/2008

Jason S Wong Sr. DBA IT Applications Manager DBA Developer Programmer M.S. Rice 88, MBA U.H. 94(MIS)

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

One of the database administrators

DEMYSTIFY TEMPDB PERFORMANCE AND MANAGEABILITY

SAP HANA - Main Memory Technology: A Challenge for Development of Business Applications. Jürgen Primsch, SAP AG July 2011

WW TSS-02\03 MS SQL Server Extended Performance & Tuning

PERFORMANCE TUNING FOR PEOPLESOFT APPLICATIONS

ABSTRACT 1. INTRODUCTION. Kamil Bajda-Pawlikowski

The Database is Slow

FHE DEFINITIVE GUIDE. ^phihri^^lv JEFFREY GARBUS. Joe Celko. Alvin Chang. PLAMEN ratchev JONES & BARTLETT LEARN IN G. y ti rvrrtuttnrr i t i r

Redpaper. Performance Metrics in TotalStorage Productivity Center Performance Reports. Introduction. Mary Lovelace

SQL Server 2012 Database Administration With AlwaysOn & Clustering Techniques

Response Time Analysis

SQL Server Performance Intelligence

Columnstore in SQL Server 2016

Physical Database Design and Tuning

Unit Storage Structures 1. Storage Structures. Unit 4.3

SQL Server Performance Assessment and Optimization Techniques Jeffry A. Schwartz Windows Technology Symposium December 6, 2004 Las Vegas, NV

1. Physical Database Design in Relational Databases (1)

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Understanding Query Processing and Query Plans in SQL Server. Craig Freedman Software Design Engineer Microsoft SQL Server

IBM DB2: LUW Performance Tuning and Monitoring for Single and Multiple Partition DBs

SQL Server. DMVs in Action. Better Queries with. Dynamic Management Views MANNING IANW. STIRK. Shelter Island

Oracle EXAM - 1Z Oracle Database 11g Release 2: SQL Tuning. Buy Full Product.

Data Integrator Performance Optimization Guide

Microsoft SQL Database Administrator Certification

PERFORMANCE TUNING WITH WAIT STATISTICS. Microsoft Corporation Presented by Joe Sack, Dedicated Support Engineer

Diagnosing and Resolving Latch Contention on SQL Server

Server 2008 SQL. Administration in Action ROD COLLEDGE MANNING. Greenwich. (74 w. long.)

Performance Implications of Various Cursor Types in Microsoft SQL Server. By: Edward Whalen Performance Tuning Corporation

SSIS Scaling and Performance

T-SQL STANDARD ELEMENTS

Response Time Analysis

Oracle Database In-Memory The Next Big Thing

Understanding SQL Server Execution Plans. Klaus Aschenbrenner Independent SQL Server Consultant SQLpassion.at

Using Database Performance Warehouse to Monitor Microsoft SQL Server Report Content

VMware vcenter 4.0 Database Performance for Microsoft SQL Server 2008

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

LearnFromGuru Polish your knowledge

Dynamics NAV/SQL Server Configuration Recommendations

Toad for Oracle 8.6 SQL Tuning

SOLIDWORKS Enterprise PDM - Troubleshooting Tools

Everything a DBA Needs to Know About Storage

Administering Microsoft SQL Server 2012 Databases

TUTORIAL WHITE PAPER. Application Performance Management. Investigating Oracle Wait Events With VERITAS Instance Watch

Controlling Dynamic SQL with DSCC By: Susan Lawson and Dan Luksetich

System Monitor Guide and Reference

Troubleshooting SQL Server A Guide for the Accidental DBA

ONSITE TRAINING CATALOG

Chapter 13: Query Processing. Basic Steps in Query Processing

An Oracle White Paper February, Oracle Database In-Memory Advisor Best Practices

DB2 LUW Performance Tuning and Monitoring for Single and Multiple Partition DBs

Boost SQL Server Performance Buffer Pool Extensions & Delayed Durability

Infor LN Performance, Tracing, and Tuning Guide for SQL Server

DB2 for Linux, UNIX, and Windows Performance Tuning and Monitoring Workshop

Performance Troubleshooting Guide for Microsoft Business Solutions Navision

Enhancing SQL Server Performance

Transcription:

Seminar 5 MS SQL Server - Performance Tuning -

Query Tuning Methodology Identify waits (bottleneck) at the server level I/O latches Log update Blocking Other Correlate waits with queues Drill down to database/file level Drill down to the process level Tune problematic queries DMV - dynamic management views 2

Identify Waits sys.dm_os_wait_stats: Returned table: wait_type Resource waits (locks, latches, network, I/O) Queue waits External waits waiting_tasks_count wait_time_ms max_wait_time_ms signal_wait_time_ms reset counters: DBCC SQLPERF ('sys.dm_os_wait_stats', CLEAR); 3

Correlate Waits with Queues sys.dm_os_performance_counters object_name - Counter category, i.e., MSSQL + $ + InstanceName: + Databases (if you have an instance) counter_name - Counter name relative to the category, which may overlap between various object_name values. instance_name - Instance of the counter which is either a database value or if it is a NULL value then the instance name is related to the overall SQL Server. cntr_value - The captured or calculated value for the counter. cntr_type - Counter type defined by Performance Monitor. 4

Correlate Waits with Queues sys.dm_os_performance_counters > 500 counters: Access Methods, User Settable, Buffer Manager, Broker Statistics, SQL Errors, Latches, Buffer Partition, SQL Statistics, Locks, Buffer Node, Plan Cache, Cursor Manager by Type, Memory Manager, General Statistics, Databases, Catalog Metadata, Broker Activation, Broker/DBM Transport, Transactions, Cursor Manager Total, Exec Statistics, Wait Statistics etc. cntr_type = 65792 cntr_value contains actual value cntr_type = 537003264 cntr_value contains real-time results need to be divided by a base to obtain the actual value. By themselves, they are useless should divide one value to base value to get a ratio, or multiply 5 that result by 100.0 to get a percentage

Correlate Waits with Queues sys.dm_os_performance_counters cntr_type = 272696576 cntr_value contains the base value Counters are time-based Counters are cumulative Use a secondary table to store intermediary values for statistics cntr_type = 1073874176 and cntr_type = 1073939712 poll both value (1073874176) and base value (1073939712) poll both values again (let s say, after 15 seconds) divide the differences between them to get the result UnitsPerSec = (cv2 cv1) / (bv2 bv1) / 15.0 6

Drill down to database/file level sys.dm_io_virtual_file_stats Returns I/O statistics for data files and log files Parameters: Database_ID (NULL = all databases), DB_ID function is useful File_ID (NULL = all files), FILE_IDEX function is useful Returned tables: Database_ID File_ID Sample_ms - # of milliseconds since the computer was started Num_of_reads - number of physical reads performed Num_of_bytes_read - number of total bytes read Io_stall_read_ms total time users waited for reads Num_of_writes - number of writes performed after the last server/services restarts Num_of_bytes_written - the number of total bytes written Io_stall_write_ms - total time users waited for writes to be completed Io_stall - sum of IO_Stall_Read_ms and IO_Stall_Write_ms File_handle 7

Drill Down to the Process Level A filter on duration/io will only isolate individual processes (batch/proc/query) More important to calculate aggregates on query pattern When using stored procedures, easy to identify pattern When not using stored procedures: Quick and dirty: LEFT(query string, n) Use a parser to identify query pattern 8

Indexes One of the major factors influencing query performance Effect on: filtering, joins, sorting, group by, blocking and dead-lock avoidance, and more Effect on modifications: positive effect on locating the rows; negative effect of cost of modification in index Understand indexes and their internals Clustered/nonclustered, single/multicolumn, indexed views and indexes on computed columns, covering scenarios, intersection 9

Indexes (cont.) Depending on environment and the ratio between SELECT queries and data modifications, you should carefully judge whether an additional index maintenance overhead is justified by query performance improvements. Multicolumn indexes tend to be much more useful than single-column indexes and the query optimizer is more likely to use them to cover the query Indexed views carry a higher maintenance cost than standard indexes WITH SCHEMABINDING option is mandatory 10

Tools to Analyze Query Performance Graphical Execution Plan STATISTICS IO: scan count, logical reads, physical reads, read ahead reads STATISTICS TIME: duration and net CPU time SHOWPLAN_TEXT: estimated plan SHOWPLAN_ALL: detailed estimated plan STATISTICS PROFILE: detailed actual plan SET STATISTICS XML: detailed actual perf info in XML format SET SHOWPLAN_XML: detailed estimated perf info in XML format (2005 only) 11

Query Optimization Evaluation of execution plans Sequence of physical/logical operations Optimization factors: Used search predicate Tables involved in joins Join conditions The size of the result List of indexes Goal: avoid worst query plans SQL Server uses a cost-based query optimizer 12

STATISTICS IO and STATISTICS TIME DBCC DROPCLEANBUFFERS clears SQL Server data DBCC FREEPROCCACHE clears procedure cache 13

STATISTICS IO and STATISTICS TIME CPU time amount of CPU resources used to execute the query Elapsed time how long the query took to execute 14

STATISTICS IO and STATISTICS TIME physical reads --number of pages read from disk 15 read-ahead reads - number of pages placed in cache for the query

STATISTICS IO and STATISTICS TIME Scan count --the number of times that tables have been accessed Logical reads - number of pages read from the data cache 16

STATISTICS IO and STATISTICS TIME USE [AdventureWorks] GO CREATE NONCLUSTERED INDEX [IDX_firstname] ON [Person].[Contact] ( ) GO [FirstName] ASC 17

STATISTICS IO and STATISTICS TIME USE [AdventureWorks] GO CREATE NONCLUSTERED INDEX [IDX_firstname] ON [Person].[Contact] ( ) GO [FirstName] ASC 18

STATISTICS IO and STATISTICS TIME 19

SHOWPLAN_ALL 20

Graphical execution plan 21

Graphical execution plan (cont.) SELECT c.customerid, SUM(LineTotal) FROM Sales.SalesOrderDetail od JOIN Sales.SalesOrderHeader oh ON od.salesorderid=oh.salesorderid JOIN Sales.Customer c ON oh.customerid=c.customerid GROUP BY c.customerid 22

Graphical execution plan (cont.) SELECT c.customerid, SUM(LineTotal) FROM Sales.SalesOrderDetail od JOIN Sales.SalesOrderHeader oh ON od.salesorderid=oh.salesorderid JOIN Sales.Customer c ON oh.customerid=c.customerid GROUP BY c.customerid 23

Graphical execution plan (cont.) 24

Graphical execution plan (cont.) SELECT oh.customerid, SUM(LineTotal) FROM Sales.SalesOrderDetail od JOIN Sales.SalesOrderHeader oh ON od.salesorderid=oh.salesorderid GROUP BY oh.customerid 25

Graphical execution plan (cont.) 26

Graphical execution plan (cont.) CREATE INDEX IDX_OrderDetail_OrderID_TotalLine ON Sales.SalesOrderDetail (SalesOrderID) INCLUDE (LineTotal) 27