New Performance Tuning Deck
New Performance Tuning Deck
New Performance Tuning Deck
A Repeatable Process –
Defining What The Issues Are
By
Frank McBath
frankmcb@microsoft.com
frankmcb@hotmail.com
Finding Queries Kill You
• See:
– www.computationpress.com
A Few Ideas
• To me, 95% of problems in databases are
driven by poor queries (SELECTs)
• 70 to 80% of escalation calls are disk drive
bottlenecks.
• I rarely start of looking at queries…
– I look at a pile of numbers…
Define the Problem(s)
• If you took your car to a mechanic…
• If you can’t define it… you can’t solve it…
• You have to get beyond “it’s slow”
Let the Computer Tell You What’s
Wrong with Itself
• Run profiler for 24 hours and search for long
running queries (LRQ)
– Surgical
• Take these queries and run them through
Database Tuning Advisor (DTA)
• Run the DMV script for missing indexes
– Shotgun
– Good… but you don’t now what originated them…
and what happens if they are one-offs and ad-hoc?
Break The Problem Up
• 50,000 lines of anything is pretty meaningless
– You rapidly get lost in the details and white noise.
• Think of things in repeating patterns
• Look for classic “80/20”
• Define things in “Top 10”
Getting A Baseline: Macro
• If you don’t have a baseline, you are just
guessing.
• Take a profiler trace. Run it for 24 hours (filter
of course!)
• Save it to a table and then do a “SUM(Reads),
Writes, Duration, CPU”
• This is a “Day in the life of your system.”
Get a Baseline: Micro
• Look at your repeating patterns and your
LRQ’s.
• Get the stats IO and stats profile on each of
these.
Baselining: Future Vision
• Run a PERFMON trace 24x7, sample every 15
minutes. Look at disk speed, RAM
consumption, and CPU.
• This can be used as a retroactive baseline.
• More importantly, you can plot this data and
“see the future” for when you need to
upgrade.
• Use this data for FY budgeting purposes.
Repro Query
• You HAVE to be able to reliably reproduce a
query outside of the application environment.
• For stored procedures, this is pretty easy.
• For ERP & CRM systems, it gets very tricky.
– SP_CURSORFETCH
– Implicit Cursor Conversions, etc…
Stats IO, Stats Profile
• SET STATISTICS IO [ON | OFF]
– Tells you at a table by table where you are getting
hit.
– Look for “Read Aheads” (aka. Scanning large
amounts of data)
• SET STATISTICS PROFILE [ON | OFF]
– This will show you at a statement by statement
level which lines are the most expensive.
– This is as accurate as you can get.
Collecting The Data
• Health Check Script
• Profiler Traces
– Keep it minimal
• Perfmon Traces
– Keep it minimal
• Don’t get lost in the white noise
• It’s like a NASCAR mechanic’s garage…
Health Check Script (I)
• Look at physical RAM, number of cores
1 ProductName NULL Microsoft SQL Server
2 ProductVersion 589824 9.00.3239.00
3 Language 1033 English (United States)
4 Platform NULL NT AMD64
5 Comments NULL NT AMD64
6 CompanyName NULL Microsoft Corporation
7 FileDescription NULL SQL Server Windows NT - 64 Bit
8 FileVersion NULL 2005.090.3239.00
9 InternalName NULL SQLSERVR
10 LegalCopyright NULL © Microsoft Corp. All rights reserved.
11 LegalTrademarks NULL Microsoft® is a registered trademark
of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation
12 OriginalFilename NULL SQLSERVR.EXE
13 PrivateBuild NULL NULL
14 SpecialBuild 212271104 NULL
15 WindowsVersion 248381957 5.2 (3790)
16 ProcessorCount 16 16
17 ProcessorActiveMask 16 ffff
18 ProcessorType 8664 NULL
19 PhysicalMemory 32765 32765 (34356162560)
20 Product ID NULL NULL
Health Check Script (II)
• SP_CONFIGURE
• I’m looking at these values…
– Compare these to the previous screen… what do
you see?
awe enabled 0 1 0 0
max degree of parallelism 0 64 1 1
max server memory (MB) 16 2147483647 14336 14336
min server memory (MB) 0 2147483647 4196 4196
xp_cmdshell 0 1 0 0
Health Check(III)
Distribution of the Workload
• 95 to 98% Reads…
– How would this impact our disk architecture?
Number of SELECT Bytes Read Bytes Written
---------------- --------------------------------------- -----------------
2946 491296440320 644440064
WHERE
((T1.TEST_ORDER_FLG = ''N'') AND
(T2.NAME = ''Sale'' OR T2.NAME = ''Return'' OR T2.NAME = @P2 OR T2.NAME =
''Exchange'' OR T2.NAME = ''Invoice'' OR T2.NAME = ''RMA - Over Shipped'') AND
(T1.X_CUST_ACC = @P3 OR T1.X_CUST_ACC = @P4 OR T1.X_CUST_ACC = @P5 OR
T1.X_CUST_ACC IS NULL OR T1.X_CUST_ACC IS NULL OR T1.X_CUST_ACC IS NULL OR
T1.X_CUST_ACC IS NULL )) AND
(T1.STATUS_CD LIKE @P6)
ORDER BY
T4.BU_ID DESC, T4.ORDER_DT DESC
Summary
• At this point, you have defined your:
– Top 10 by table, index, LRQ
– Looked over the system configuration RAM,
MAXDOP
– Looked over the disk architecture at a logical level,
and physical (ms/io, HA & Performance)
• Now the issues have been defined.
– Use DTA to start fixing them.