SQL Server Internals & Architecture

advertisement
SQL SERVER INTERNALS &
ARCHITECTURE
Kevin Kline, SQL Sentry
Director of Engineering Services, kekline@sqlsentry.com
Microsoft SQL Server MVP since 2003
Twitter , Facebook, LinkedIn @ KEKline
Website: http://KevinEKline.com/, http://ForITPros.com
FOR FRIENDS OF SQL SENTRY
•
Free Plan Explorer download:
http://www.sqlsentry.net/plan-explorer/
•
Free query tuning consultations:
http://answers.sqlperformance.com.
•
Free new ebook (regularly $10) to attendees.
Send request to sales@sqlsentry.net.
•
SQL Server educational videos, scripts, and
slides: http://SQLSentry.TV
•
Tuning blog: http://www.sqlperformance.com/
•
Monthly eNews tips and tricks:
http://www.sqlsentry.net/newsletter-archive.asp
DROPPING ACID - WHY DOES SQL SERVER
DO WHAT IT DOES?
• ACID properties of Transactions
o
o
o
o
Atomic
Consism tent
Isolated
Durable
• Speed, scalability, and
performance; Maximize hardware
• Competitive features
OUR TOUR GUIDE
Talk nerdy
to me, baby!
OK, WE’RE
DONE
Query
Tree
SELECT
Language
Event
Protocol
Layer
Relational Engine
Cmd Parser
Optimizer
Query
Plan
SNI
Query
Executor
TDS
TLog
OLE
DB
?
Storage Engine
Data
File
Transaction
Manager
Access
Methods
Buffer
Manager
?
SQL Server
Network
Interface
Buffer Pool
-----------Data Cache
-----------Plan Cache
SQLOS AND SCHEDULERS
• 1 Cash Register = 1 SchedulerUh oh!
The out
• Users are assigned
of soda!
to a thread
No problem. Step
aside… More
syrup for the
sodas!
Yeah!
I’m next
in line!
Goes to the waiting, i.e.
“suspended queue”
TROUBLESHOOTING WAIT
STATS?
SOS_Scheduler_Yield
Query
Tree
Writelog, Logbuffer
Relational Engine
Cmd Parser
Optimizer
Query
Plan
SQL
OS
Pagelatch_x,
Latch_x,
SQL
Server
Resource_Semaphore
TDS
?
Storage Engine
Check
Point
Trans-action
Manager:
Log & Lock
Mgr
Data
File(s)
Locks
Access
Methods
Data
Write
LCK_x, Lazywriter
LCK_M_x
Protocol
Layer
SNI
Query
Executor
PageIOLatch_x,
OLE
Async_IO_Completion,
DB
IO_Completion
TLog
Async_Network_IO
Language
Event
Buffer
Manager
?
Network
Interface
Latches
Buffer Pool
-----------Data Cache
-----------Plan Cache
CACHES?
• How long does a page of data or
a block of code stay in cache?
• Uses a LRU algorithm
• Usually performed by the lazywriter, but can also be done by
any worker thread after
scheduling its own I/O
CACHE AGING & LRU-K BEHAVIOR
Memory
getord
16
14
12
16
13
15
finduser
7
What about
buffer cache?
sp_1
3
3
1
0
2
7
4
5
6
sp_4
2
2
1
0
BUT WAIT!
THERE’S MORE!
Query
Tree
Language
Event
Protocol
Layer
Relational Engine
Cmd Parser
Optimizer
Query
Plan
INSERT,
UPDATE,
or
DELETE
SNI
Query
Executor
TDS
TLog
CheckPoint
Data
File
OLE
DB
?
Storage Engine
Transaction
Manager:
Log & Lock
Mgr
Access
Methods
Data
Write
Buffer
Manager
?
Lazywriter
SQL Server
Network
Interface
Buffer Pool
-----------Data Cache
Oooh! So
dirty!
-----------Plan Cache
HEKATON, A.K.A.
IN-MEMORY OLTP
Query
Tree
Language
Event
Relational Engine
Cmd Parser
Optimizer
Query
Plan
SQL
OS
Protocol
Layer
SNI
Query
Executor
TDS
TLog
OLE
DB
?
Storage Engine
Check
Point
Trans-action
Manager:
Log & Lock
Mgr
Data
File(s)
Locks
Access
Methods
Data
Write
Lazywriter
Buffer
Manager
?
SQL Server
Network
Interface
Latches
Buffer Pool
-----------Data Cache
-----------Plan Cache
SUMMARY
Download