Professional Documents
Culture Documents
SQL Server Performance Internals For DBAÆs
SQL Server Performance Internals For DBAÆs
for DBA’s
Gert E.R. Drapers
Software Architect
SQL Server Development
Performance
When under load, every system has a bottleneck
that limits performance
In real systems as utilization 100%, other factors
provide back pressure (for example: Only so many
connections to service)
May depend on workload, time of day
For example OLTP, Decision Support and Batch may
have different profiles and bottlenecks
Everything slows down due to bottleneck; fix one
bottleneck, and another surfaces under load
CPU, I/O, Locking (concurrency), Network
In a perfect world, CPU is the last bottleneck!
So, how do you find the bottleneck?
Look for longest queues and response times…
Scalability Rules
Database scalability is limited by the
maximum throughput of the transaction log
Disk I/O
Instance scalability is limited by shared
“process” level resources
Memory
Server scalability is limited by shared
“server”/”machine” level resources
CPU (incl. L1 & L2 cache)
Network bandwidth
Architecture TDS Packets
Network Libraries
Relational Engine
Language RPC
Open Data Services (ODS)
Events Events
User Mode Scheduler (UMS)
Parser
Expression Manager
Query SQL
Compiler
Optimizer Manager
SQL Executor
Normalizer
Databases
User
User
User
User
UserDBs
User tempdb
TempDB master
Master msdb
MSDB
How to determine bottlenecks?
Distinct Queues and Waits
Queues
Outstanding (unfulfilled) resource requests
Performance Monitor counters, measure resource utilization
(e.g. Avg Disk Queue Length)
SQL Waits
Anytime a SQL thread is not executing, a wait type is set
reflecting the reason for waiting
Waits from an Application or User connection perspective
76 distinct wait types for SQL Server 2000
Queues and Waits are complementary information
Together, explain application performance
Both are essential for problem determination
Performance Monitor counters provide a view of
system performance from a resource standpoint
Wait types and sysprocesses
If a worker thread is not currently executing, a wait
type or state is set in sysprocesses
sysprocesses contains:
lastwaittype
waitype
waittime
Example:
select spid, blocked, waittype, waittime, lastwaittype
from master.dbo.sysprocesses
where spid > 51
Limitation: Transience of sysprocesses, spid
history
Wait types and dbcc sqlperf()
dbcc sqlperf(waitstats, [clear])
Cumulative wait types and times
Limitations: Relevance of types and what you
can control?
DBCC SQLPERF (WAITSTATS)
Wait Type Requests Wait Time Signal Wait Time
----------------------- ------------------------ ------------------------ ----------------
MISCELLANEOUS 0.0 0.0 0.0
LCK_M_SCH_S 0.0 0.0 0.0
LCK_M_SCH_M 0.0 0.0 0.0
LCK_M_IX 0.0 0.0 0.0
SLEEP 804037.0 8.0404858E+8 8.0404858E+8
IO_COMPLETION 132.0 20763.0 3201.0
ASYNC_IO_COMPLETION 4.0 4109.0 0.0
RESOURCE_SEMAPHORE 0.0 0.0 0.0
DTC 0.0 0.0 0.0
OLEDB 1.0 62.0 0.0
PIPELINE_INDEX_STAT 0.0 0.0 0.0
PIPELINE_LOG 0.0 0.0 0.0
PIPELINE_VLM 0.0 0.0 0.0
WRITELOG 14.0 2407.0 15.0
PSS_CHILD 0.0 0.0 0.0
CMEMTHREAD 24.0 0.0 0.0
CXPACKET 0.0 0.0 0.0
PAGESUPP 0.0 0.0 0.0
SHUTDOWN 0.0 0.0 0.0
WAITFOR 0.0 0.0 0.0
dbcc sqlperf()
Syntax:
dbcc sqlperf (<key>) tableresults, no_infomsgs
Options:
umsstats – SQL thread management (*)
waitstats – resources, wait types (*)
iostats – outstanding reads & writes (*)
rastats – read ahead activity (*)
threads – I/O / CPU / memory usage per thread
(*) = Undocumented!
Resetting the counters:
dbcc sqlperf (<key>, clear) with no_infomsgs
Wait types explained
See
http://SQLDev.Net/misc/waittypes.htm
KB article 822101
Correlating Waits & Queues:
I/O or Memory Pressure?
Waits Queues Explanation
IO_Completion 1. SQL Buffer Mgr Waits indicate I/O issue
Async_IO_Completion Avg Page Life High Avg disk seconds
PageIOLatch_x Expectancy (seconds) indicates I/O issue
PageLatch_x Checkpoint HOWEVER Low average
pages/sec page life indicates
Lazywrites/sec memory pressure e.g.
cache flushing
2. Physical Disk
Avg disk sec/read
Avg disk sec/write
Disk queues
Correlating Waits & Queues:
I/O or DB Design?
Waits Queues Explanation
1. IO_Completion 1. SQL Buffer Mgr 1. If Profiler shows:
Avg Page Life Scan started
2. Async_IO_Completion Expectancy (seconds) Reads
Checkpoint Writes
pages/sec
3. Writelog 2. If Showplan shows
Lazywrites/sec
Table scans
2. Physical Disk
Clustered index
Avg disk sec/read range scans
Avg disk sec/write Nonclustered index
Disk queues range scans
Sorts
dbcc sqlperf(umsstats)
SQL Server implements its own cooperative scheduler
UMS = User Mode Scheduler
Underneath uses native Win32/64 threads or fibers
Fiber support is enable via sp_configure
exec sp_configure 'lightweight pooling', [0|1]
dbcc sqlperf (umsstats) will show UMS statistics including
runnable queue length
Output dbcc sqlperf(umsstats)
Statistic Value
Scheduler ID 0.0
num users 8.0
num runnable 0.0
num workers 6.0
idle workers 3.0
work queued 0.0
cntxt switches 383453.0
cntxt switches(idle) 1807557.0
dbcc sqlperf(umsstats)
Item Definition
num users Number of SQL threads on the scheduler