Upload
krishnakumar-s
View
240
Download
1
Embed Size (px)
DESCRIPTION
This is an introduction to Microsoft SQL Server In-memory Engine that was earlier code named Hekaton. It describes the basic concepts and technologies involved in the in-memory engine - This has presented in Kerala - Microsoft Users Group Meeting on May 31, 2014
Citation preview
An introduction to SQL Server In-Memory OLTP
Krishnakumar S
Traditional OLTP Architecture
•Disk is cheap – Data lives in disk•Memory is fast – Data modified in memory (Buffer) •Disk to Memory – I/O utilization•Query processing – CPU & Memory utilization•ACID – I/O utilization
Write ahead log, Transaction Log CPU utilization (Locking, latching)
•Memory to Disk – I/O utilization (Dirty pages to disk – Checkpoint)
High volume data modifications
Traditional OLTP Architecture
Contentions – “Competition for resources”
• Lock• Latch• Disk I/O• Allocation
AirlinesSensor dataApplication loggingConversations
etc…
CPU vs. Memory vs. I/O
Changing scenario…..
CPUStill hold Moor’s lawBecoming fasterMulticore
MemoryGetting cheaperBecoming fasterHold more data
I/OLagging far behindCPU and Memory
“The Free lunch is over…” – Herb Sutter, Dr. Dobb’s Journal, March 2005
“Tape is dead Disk is Tape Flash is Disk…” – Jim Gray, Microsoft, Dec 2006
SQL Server 2014 In-memory OLTP Engine
Goal was to achieve 100x speedup for certain TP operations
Hekaton a Greek word for 100
Microsoft spend nearly seven years on Hekaton
A major change in SQL Server engine from version 7.0
Four architectural pillars
SQL Server 2014 In-memory OLTP Engine
1. Optimize for main memory data access2. Accelerate business logic processing3. Provide frictionless scale-up4. Built-in to SQL Server
Optimize for main memory
SQL Server 2014 In-memory OLTP Engine
1. No 8KB pages for tables; only stream of bytes2. New lock and latch free in-memory indexes
1. Hash index (equality)2. Bw index (range) [“Buzz Word” index]
3. Using MVCC (Muti-Version Concurrency control); transactions see a snapshot of data
4. Log, data changes to transaction log5. No logging for index changes; recreates when
server restart
Accelerate business logic processing
SQL Server 2014 In-memory OLTP Engine
1. Table and index metadata compiled to DLL1. Table row format preserved in DLL2. Traditional query engine can be leveraged to access in-
memory tables 2. Stored Procedure compiled to DLL
Frictionless scale-up
SQL Server 2014 In-memory OLTP Engine
1. Multi-version optimistic concurrency control with ACID support
2. Lock free algorithms for in-memory engine3. No lock manager, latches or spin lock
Built-in to SQL Server
SQL Server 2014 In-memory OLTP Engine
1. In-memory engine is integrated in to SQL Server2. Both memory optimized and traditional tables can be
created for a database3. No lock manager, latches or spin lock
In-memory OLTP Engine – Behind the scenes
Rows
In-memory OLTP Engine – Behind the scenes
• Row Header– BeginTS
• TX TS that created the row– EndTS
• TX TS that deleted the row• Infinity
– StmtID• Statement that created the row
– IdxLinkCount• Number of indexes that reference this row
• Payload = actual data
TxID global DB counterReset on restartIncremented on TX start
TxTimeStamp global DB counter
Not reset on restartIncremented on TX end
Rows – Hash index
In-memory OLTP Engine – Behind the scenes
Hash index on Name
f(John)
Timestamps NameChain ptrs City
90, ∞ Susan Bogota
50, ∞ John Paris
Transaction 99:SELECT City WHERE Name = ‘John’Simple hash lookup returns direct pointer to ‘John’ row
100, ∞ John Prague
50, 100
Transaction 100: UPDATE City = ‘Prague’ where Name = ‘John’No locks of any kind, no interference with transaction 99
Rows – Non clustered index
In-memory OLTP Engine – Behind the scenes
Rows – Non clustered index
In-memory OLTP Engine – Behind the scenes
Addr.
0
1
2
3
4
…
Page Mapping Table
Page P
Δ Inserted Record 50
Δ Deleted record 48
Delta record
Delta record
PID
0
1
2
3
4
…
4.14.2
In-memory OLTP Engine – Summary
• T-SQL Features– 2 ways to access in-memory tables
• T-SQL interop (usually slower)• Natively compiled stored procedures (fast)
• T-SQL non supported features– TRUNCATE Table– MERGE (when in-memory table is the target)– Linked servers– Locking hints: TABLOCK, XLOCK, PAGLOCK, etc.
• NOLOCK is supported, but is quietly ignored
In-memory OLTP Engine – Summary
• Stored Procedures– TRY, CATCH, error functions, IF, WHILE– Memory-optimized table types and table variables– Math, Date, String functions – SCOPE_IDENTITY, ISNULL, NEWID,
NEWSEQUENTIALID
In-memory OLTP Engine – Summary
• Common Design patterns– In-Memory OLTP– High-performance OLTP– High data input or ”Shock Absorber”– Relational cache– Read-scale– ETL target and staging/temp tables
Demo
Questions?
Thank You