47
PERFORMANCE TUNING FOR PIRATES! HTTP://JOHNSTERRETT.COM/GO/PERFORMANCE John Sterrett (@JohnSterrett)

Performance Tuning for Pirates!

Embed Size (px)

DESCRIPTION

This is the slide deck for my #24hop session on Performance Tuning for Pirates.

Citation preview

Page 1: Performance Tuning for Pirates!

PERFORMANCE TUNING FOR

PIRATES!

HTTP://JOHNSTERRETT.COM/GO/PERFORMANCE

John Sterrett (@JohnSterrett)

Page 2: Performance Tuning for Pirates!

ABOUT John…

I am a Remote DBA Expert • Responsible 100+ Instances of SQL Server

• Senior DBA on Integration Team

Mid-Atlantic Region Mentor

Founder of WVPASS (SQL UG)

Host of SQL Saturday #36 and #80

I reside in Wheeling, WV (Pittsburgh, PA)

2

Page 3: Performance Tuning for Pirates!

Pirates and Yankees

Photos: http://www.flickr.com/photos/jaubele1/4299542394/ and http://www.flickr.com/photos/wenzday01/2537854102

3

Page 4: Performance Tuning for Pirates!

Objectives

• Eliminate the Obvious

• Know the process

• Know the common bottlenecks

• Know your Tools – Wait Stats

– Performance Monitor & PAL (WMI Counters)

– DMV’s and scripts

– SQL Server Side Trace (SQL Profiler)

– Clear Trace

– SQL Diag

– SQL Nexus

– RML Utilities

• ReadTrace

• Ostress

• Know where to go for help...

4

Page 5: Performance Tuning for Pirates!

Eliminate the Obvious

5

Page 7: Performance Tuning for Pirates!

Know the process!

Generate workload

Capture workload

Analyze captured workload

Make Changes

7

Page 8: Performance Tuning for Pirates!

12 Steps to workload Tuning

8

Page 9: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

9

Page 10: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

10

Page 11: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

*** Done with Production ***

11

Page 12: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

12

Page 13: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

13

Page 14: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

14

Page 15: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

15

Page 16: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

8. Restore Backup on Test Server

16

Page 17: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t

Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

8. Restore Backup on Test Server

9. Make Changes to Improve Performance on Test Server

17

Page 18: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

8. Restore Backup on Test Server

9. Make Changes to Improve Performance on Test Server

10. Prepare to Capture Production Workload on Test Server

18

Page 19: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

8. Restore Backup on Test Server

9. Make Changes to Improve Performance on Test Server

10. Prepare to Capture Production Workload on Test Server

11. Replay Workload on Test Server

19

Page 20: Performance Tuning for Pirates!

12 Steps to workload Tuning

1. Backup Production Database

2. Capture Production Workload

3. Analyze Workload and Script Changes (Don’t Implement)

4. Restore Backup on Test Server

5. Prepare to capture Workload on Test Server

6. Replay Production Workload on Test Server

7. Analyze to Establish Baseline

8. Restore Backup on Test Server

9. Make Changes to Improve Performance on Test Server

10. Prepare to Capture Production Workload on Test Server

11. Replay Workload on Test Server

12. Analyze and Compare Workload with Baseline

*** Repeat Steps 8 to 12 as needed ***

20

Page 21: Performance Tuning for Pirates!

Where can things Go wrong?

21

Page 22: Performance Tuning for Pirates!

Meet the Bottlenecks

Photos: http://www.flickr.com/photos/kaiban/5159888367/lightbox/ and http://www.flickr.com/photos/moodog/504456253 and http://www.flickr.com/photos/marksze/4231115464 and http://www.flickr.com/photos/vvvracer/5264339383 and http://www.flickr.com/photos/iphil_photos/4962369046

MEMORY DISK (SPINDLES) CPU

NETWORK LOCKING, BLOCKING & DEADLOCKS

22

Page 23: Performance Tuning for Pirates!

3 Options To Resolve bottlenecks

23

Page 24: Performance Tuning for Pirates!

3 Options To Resolve bottlenecks

1. Reduce Workload

24

Page 25: Performance Tuning for Pirates!

3 Options To Resolve bottlenecks

1. Reduce Workload

2. Tune Workload to reduce bottleneck resource

25

Page 26: Performance Tuning for Pirates!

3 Options To Resolve bottlenecks

1. Reduce Workload

2. Tune Workload to reduce bottleneck resource

3. Add additional Hardware

26

Page 27: Performance Tuning for Pirates!

Viewing Wait Stats

• Sys.dm_os_wait_stats

• Wait stats can be cleared manually or during restart.

– DBCC SQLPERF(‘sys.dm_os_wait_stats’, CLEAR)

• Focus on waits dedicated to bottlenecks

27

Page 28: Performance Tuning for Pirates!

Common WAIT STATS

• ASYNC_NETWORK_IO

• LCK_M_*

• IO_COMPLETION

• PAGELATCH_* or PAGEIOLATCH_*

• WRITELOG

• CX_PACKET

• SOS_SCHEDULER_YIELD

28

Page 29: Performance Tuning for Pirates!

DEMO!!!!

• Review Wait Statistics

29

Page 30: Performance Tuning for Pirates!

Memory Performance counters

Object Counter

You Want Description

Memory Available Mbytes

> 256 MB Unused physical memory

Memory Pages Input/sec

< 10 Reads from hard disk per second to memory

SQL Server: Buffer Manager Page Life Expectancy

> 300 On average, how many seconds SQL Server expects page to say in cache (memory)

SQL Server: Memory Manager Total Server Memory (KB)

Shows amount of memory SQL Server is currently using.

SQL Server: Memory Manager Target Server Memory (KB)

Amount of memory that SQL Server wants to use based on configured max Server Memory setting

SQL Server: Memory Manager Memory Grants Pending

0 Total number of processess pers second waiting for workspace memory grants

SQL Server: Buffer Manager Free Pages

> 640 Total number of pages avaiable across all free lists. A value under 640

SQL Server: Buffer Manager LazyWrites/Sec

< 20 Number of times per second that the lazywritter process moves dirty page from buffer to disk.

30

Page 31: Performance Tuning for Pirates!

Disk Performance Counters

Object

Counter

You Want Description

Physical Disk Avg Disk Sec/Read

< 25ms

Avg. Disk sec/Read is the average time, in seconds, of a read of data from the disk.This

analysis determines if any of the physical disks are responding slowly.

Physical Disk Avg Disk Sec/Write

< 25ms

Avg. Disk sec/Write is the average time, in seconds, of a write of data to the disk.

Physical Disk Disk Reads/sec

Disk Reads/sec is the rate of read operations on the disk.

Physical Disk Disk Writes/sec

Disk Writes/sec is the rate of write operations on the disk.

• The sys.dm_io_virtual_file_stats DMV can be used to get disk latency for individual sql server files.

31

Page 32: Performance Tuning for Pirates!

CPU Performance Counters

Object

Counter

You Want Description

Process (sqlservr) %Processor Time

< 80% Percentage of processor time spent on SQL Server process threads.

Processor %Processor Time

< 80% Percentage of elapsed time the processor spends executing non-idle threads.

32

Page 33: Performance Tuning for Pirates!

General Workload performance

counters

Object

Counter

You Want Description

SQL Server: SQL Statistics Batch Requests/Sec (SQL2005/08)

Number of SQL batch requests received by server. This counter measures the number of batch requests that SQL Server receives per second, and generally follows in step to how busy your server's CPUs are.

SQL Server: SQL Statistics SQL Compilations/sec

< 10% of the number of batch request/sec

Number of SQL compilations.

SQL Server: SQL Statistics SQL Re-Compilations/sec

< 10% of the number of compilations/sec

Number of SQL re-compiles. This needs to be 0 as much as possible. A recompile can cause deadlocks and compile locks that are not compatible with any locking type.

SQL Server: SQL Statistics User Connections

SQL Server: Access Methods Full Scans/sec

1 Full scan for every 1000 index searches

This counter monitors the number of full scans on base tables or indexes. High values indicate that we may be having performance issues due to table / index page scans.

SQL Server: Access Methods Index Searches/sec

This counter measures the number of index searches per second. Index searches are used to start range scans, single index record fetches, and to reposition within an index. Index searches are preferable to index and table scans.

SQL Server: Access Methods Page Splits/sec

Number of page splits per second that occur as a result of overflowing index pages. Reduce non-sequential inserts or use fill factor and pad_index to leave more empty space per page.

33

Page 34: Performance Tuning for Pirates!

Locking Performance Counters

Object

Counter

You Want Description

SQL Server: Locks Number of Deadlocks/sec

<1

Number of lock requests per second

that resulted in deadlock.

SQL Server: Locks Table Lock Escalations/sec

Number of times SQL escalated

locks to table level. This can indicate

poorly coded transactions.

SQL Server: Locks Avg Wait Time (ms)

< 500

The average wait time for each lock

request that had to wait.

SQL Server: General Statistics Processes blocked

Number of currently blocked

processes.

34

Page 35: Performance Tuning for Pirates!

DEMO!!!

• Review Perfmon

• Review PAL Tool – Collection Process

– Generating Reports

– Reviewing Reports

35

Page 36: Performance Tuning for Pirates!

Execution DMV’s

• Sys.dm_exec_session – Returns one row per authenticated session, including user and

system processes.

• Sys.dm_exec_requests – Returns one row for each request executing within SQL Server,

doesn’t include code executed outside of SQL (distributed queries, extended stored procedures etc…)

• Sys.dm_exec_query_stats – Returns one row per query statement with cached plan, detailing

aggregated performance stats for cached plans.

• Sys.dm_exec_connections – Returns server information about a connection to SQL Server

including client network address, TCP Port etc..

36

Page 37: Performance Tuning for Pirates!

Query details DMV’S

• Sys.dm_exec_sql_text

– Returns the text of the SQL Server batch that is identified by

specific sql handle.

• Sys.dm_exec_text_query_plan

– Returns the showplan output in text format.

• Sys.dm_query_plan

– Returns a given query’s showplan output in xml.

37

Page 38: Performance Tuning for Pirates!

INDEX DMV’s

• Sys.dm_db_index_usage_stats

– Returns a count of index operations including seeks, scans, lookup

and updates

• Sys.dm_db_index_physical_stats

– Returns size and fragmentation information for data pages and

indexes.

• DMV’s to find recommended indexes

– Sys.dm_db_missing_index_columns

– Sys.dm_db_missing_index_details

– Sys.dm_db_missing_index_groups

– Sys.dm_db_missing_index_group_stats

38

Page 39: Performance Tuning for Pirates!

SQLOS DMV’s

• Sys.dm_os_sys_memory

– Returns complete picture of memory at the os level including total and available memory.

• Sys.dm_os_tasks

– Returns a row for each OS task thais is active in the instance of SQL Server.

• Sys.dm_os_threads

– Returns a row for each SQLOS thread running under the SQL Server process.

• Sys.dm_os_performance_counters

– Returns a row for each SQL Server perfmon counter.

• Sys.dm_os_waiting_tasks

– Returns information about the wait queue of SQLOS. This would be tasks waiting on resources like blocking and latch contention etc..

39

Page 40: Performance Tuning for Pirates!

DMV Queries (DEMO)

• What is Running?

• Probing the Proc Cache

http://www.flickr.com/photos/democonference/4458079104

40

Page 41: Performance Tuning for Pirates!

SQL Profiler (DEMO!)

• Generate Server Side traces

– Tuning Columns and Events

– Remove the noise

• Read Trace with Clear Trace

http://www.flickr.com/photos/democonference/4458079104

41

Page 42: Performance Tuning for Pirates!

SQL Diag (DEMO)

http://www.flickr.com/photos/democonference/4458079104

• Review SQL Diag

• Review PerStats Scripts

• Collect perfmon, sql trace, blocking and more…

42

Page 43: Performance Tuning for Pirates!

SQL NEXUS (DEMO)

• Import SQLDiag

• Analysis collected data

http://www.flickr.com/photos/democonference/4458079104

43

Page 44: Performance Tuning for Pirates!

RML Utilities (DEMO)

• Ostress (Replay)

• ReadTrace (Compare Workload to Baseline)

http://www.flickr.com/photos/democonference/4458079104

44

Page 45: Performance Tuning for Pirates!

Help I need Some One!!!!

• Performance Virtual Chapter

– http://performance.sqlpass.org/

• Twitter (#sqlhelp)

• Message boards

– www.sqlservercentral.com

– www.msdn.com

• Blogs

• Consultants

45

Page 46: Performance Tuning for Pirates!

Where to go next?

• HTTP://JOHNSTERRETT.COM/GO/PERFORMANCE

– Videos

– Reference Links

– Slides

46

Page 47: Performance Tuning for Pirates!

Thank You to our Sponsors