Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
6/12/2007
Agenda
SQL-OS
Scheduler
Wait States
6/12/2007
6/12/2007
Performance Layers
Physical I/O
Locking
Logical I/O
Networking
Query
Requests
6/12/2007
NET
Users /
Sessions
LOCKS
Object
Access
LIO
Cache
(Buffer
Pool)
PIO
Physical
Storage
What is SQLOS
Thin user-mode layer between server and
OS:
Scheduler and IO completion
Synchronization primitives
Memory Management
Resource Management
Deadlock Detection
Exception Handling Framework
Hosting (Services for external components)
6/12/2007
OS Abstraction layer
Does not wrap all OS APIs (like .NET)
Platform neutral bridge to other OSs.
Component Library
No general purpose classes or functions
Does not define rules for programming
6/12/2007
6/12/2007
What is SMP
SMP Symmetric Multi-Processing
Front-bus point of contention
Difficult to scale beyond 32 CPU
Memory
Front-bus
CPU 0
CPU 1
...
CPU n
What is NUMA
CPU 0
CPU 1
CPU 2
CPU 3
CPU
Memory
CPU
CPU
CPU n
What is Interleaved-NUMA
all nodes
CPU 0
CPU 1
CPU 2
Memory
CPU 3
CPU
CPU
Foreign Memory
CPU
CPU n
What is Soft-NUMA
Activates custom NUMA configuration on top
of any of hardware
Registry settings control final SoftNUMA
configuration
Provides greater performance, scalability,
and manageability on SMP as well as on real
NUMA hardware
6/12/2007
11
NUMA Node
Memory
CPU
CPU 1
CPU 2
CPU 3
SOS Node
SOS
Memory
Node
Scheduler
6/12/2007
Scheduler
Scheduler
Scheduler
12
Server Architecture
SQLOS API
Protocols
Query Comp. and Execution Engines
SQLOS API
Resource
Monitor
Lazy
Writer
Scheduler
Monitor
SQLOS
Hosting API
Deadlock
Monitor
Lock
Manager
External Components
Storage Engine
Synchronization
Buffer
Pool
Scheduling
I/O
Memory Manager
= thread
6/12/2007
13
Agenda
SQL-OS
Scheduler
Wait States
6/12/2007
14
SOS Scheduler
usage scenarios
6/12/2007
15
Benefits of Scheduler
6/12/2007
16
SOS - Node
Maps to a single NUMA node or SMP box
Collection of CPUs (Schedulers)
Memory Node
Scheduler Management and Monitoring
4-Way SMP
2-Node NUMA
6/12/2007
17
CPU n
Sched 0
Sched n
SOS Node
Tasks
6/12/2007
Scheduler
Work
Dispatcher
Sched 1
Tasks
Scheduler
Work
Dispatcher
Sched 2
Tasks
Tasks
SOS
Schedules
Tasks
Scheduler
Work
Dispatcher
Scheduler
Work
Dispatcher
18
Scheduling subsystem
Task
Execution unit maps to thread or fiber
Scheduler
Provides non-preemptive scheduling and task pool
In SS2K a connection was assigned to a UMS and stayed there and in
SS2005, a thread within a connection is what is assigned to a UMS
NUMA node
Provides node locality and pool of real threads
Synchronization objects
Library of synchronization objects built on top of non-preemptive
scheduling
Exception handling
6/12/2007
19
SOS Scheduler
Fiber Mode
Task (n)
Task (n)
Worker (m)
Worker (m)
SystemThread (m)
SystemThread (k<m)
OS Thread
OS Thread
System Threads
Data structure describing Physical Thread.
Used to execute thread or fiber.
All threads created in SOS Process are
associated with SOS on creation.
6/12/2007
21
Workers
Data structure representing logical thread
It is associated with a scheduler
Workers created on demand up to a
configured limit
Free workers remain in a worker pool
Free workers can shrink after a timeout or on
memory pressure
Free workers can be migrated between
schedulers, Non-free workers do not migrate
between schedulers.
6/12/2007
22
Tasks
6/12/2007
23
Preemptive mode
SOS Switch to preemptive mode
Code that could block outside of server (NT APIs)
Code we have no control over (XPs, DQ)
context of scheduler
SOS APIs can be called from preemptive mode
6/12/2007
24
Scheduler Architecture
Idle worker
Current worker
Runnable Queue
Worker Dispatcher
Worker Pool
Scheduler
Timer Queue
Pending Queue
Wake event
Aborted Task List
IO Queues
6/12/2007
25
Resource Utilization
Execution model: Queues & Lists (simplified)
Running - 1/SQLOS
SPID
60
IO_Completion
SPID 51
60 Running
(Signal Waits)
SPID 51
SPID 64
SPID 87
SPID 52
SPID 93
Runnable
Runnable
Runnable
Runnable
Runnable
SPID 73 LCK_M_S
SPID 59 NETWORKIO
SPID 56 CXPACKET
Runnable
SPID 55 RESOURCE_SEMAPHORE
2
3
1, 5
2
UMS
3
4
UMS
UMS
UMS
4 way CPU
6/12/2007
27
1
Schd
2
3
Threads
Not
Connections
Schd
Schd
Schd
4 way CPU
6/12/2007
28
I/O completion
completion port
Node based API.
6/12/2007
29
6/12/2007
30
Agenda
SQL-OS
Scheduler
Wait States
6/12/2007
31
RUNNING!
Switched
No new
request
Yield
Runnable List
New
request
WorkerPool
Timer
Request
Expired/
signaled
Timer
List
Resource
available
Created
Resource
Waiter List
15 min idle
Dead
6/12/2007
32
signaled
Once the waiter is running again the resource is
actually being used
6/12/2007
33
77 wait states
6/12/2007
34
Requests
Number of times the wait state was entered
Not number of time resource got used!
Time
35
Waits
Anytime a SQL thread is not executing, a wait type is set
information
Both are essential for problem determination
Together, explain application performance
6/12/2007
36
Summary
6/12/2007
37
6/12/2007
38