14
SQL SERVER IN-MEMORY INTERNALS By Hamid J. Fard Microsoft Certified Master: SQL Server 2008 Microsoft Certified Solutions Master: Charter-Data Platform CIW Database Design Specialist ghts © 2016 Fard Solutions Sdn Bhd, All rights reserved.

SQL Server In-Memory Internals and Performance Tips

Embed Size (px)

Citation preview

Page 1: SQL Server In-Memory Internals and Performance Tips

SQL SERVER IN-MEMORY INTERNALS

By Hamid J. FardMicrosoft Certified Master: SQL Server 2008

Microsoft Certified Solutions Master: Charter-Data PlatformCIW Database Design Specialist

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 2: SQL Server In-Memory Internals and Performance Tips

Agenda• What is In-Memory OLTP?• In-Memory OLTP Components.• Memory-Optimized Table Requirements.• Memory Optimized Tables.• Memory Optimized Indexes.• In-Memory Query Processing.• In-Memory Transactions.• In-Memory Memory Estimation.• In-Memory Filegroup Configuration.• In-Memory Data and Delta File Population.

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 3: SQL Server In-Memory Internals and Performance Tips

What is In-Memory OLTP?

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

In-Memory Table

Disk Based Table

Benefits:• Eliminate contention.• Reduce logging.• Lower latency data retrieval.• Minimize code execution time.• Efficient data retrieval.• Optional IO reduction or removal,

when using non-durable tablesImplementation Scenarios:• High data insertion rate from

multiple concurrent connections.• Read performance and scale with

periodic batch inserts and updates.• Intensive business logic processing

in the database server.• Low latency.• Session state management.

Page 4: SQL Server In-Memory Internals and Performance Tips

In-Memory OLTP Components

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

In-MemoryPerformance

Page 5: SQL Server In-Memory Internals and Performance Tips

Memory-Optimized Table Requirements.

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Hardware Software

• X64 Architecture Processor• <60 Processor Cores• Enough Memory (x2 Table Size)• Enough Storage (x2 Table Size)• Processor Needs to Support

cmpxchg16b

• X64 Architecture Edition• Enterprise or Developer Edition• Hyper-V to Support cmpxchg16b (If

needed)• Enable Instant File Initialization

Page 6: SQL Server In-Memory Internals and Performance Tips

Memory Optimized Tables.

SQL Server CLR In-Memory Table

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 7: SQL Server In-Memory Internals and Performance Tips

Memory Optimized Indexes.

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Made for point lookups Made for range scans and ordered scans

Page 8: SQL Server In-Memory Internals and Performance Tips

In-Memory Query Processing

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Disk Based Query Plan SQL Server Query Processing for Disk-Based Tables

INTerpreted Transact-SQL Access to Memory-Optimized TablesMemory Optimized Query Plan

Page 9: SQL Server In-Memory Internals and Performance Tips

In-Memory Query Processing (Cont.)

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Native compilation of stored procedures

Execution of natively compiled stored procedures

Page 10: SQL Server In-Memory Internals and Performance Tips

In-Memory Transactions

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Lifetime of a transaction that accesses memory-optimized tables

Regular Processing Validation Phase Commit Processing

• Commit Dependency• Repeatable Read Validation• Serialization Validation

Page 11: SQL Server In-Memory Internals and Performance Tips

In-Memory Memory EstimationCREATE TABLE IMOLTP (col1 INT NOT NULL PRIMARY KEY NONCLUSTERED,col2 INT NOT NULL INDEX INDEX_1 HASH WITH (BUCKET_COUNT = 5000000),col3 INT NOT NULL INDEX INDEX_2 HASH WITH (BUCKET_COUNT = 5000000),col4 INT NOT NULL INDEX INDEX_3 HASH WITH (BUCKET_COUNT = 5000000),col5 INT NOT NULL INDEX INDEX_4 NONCLUSTERED,col6 CHAR (50) NOT NULL, col7 CHAR (50) NOT NULL, col8 CHAR (30) NOT NULL, col9 CHAR (50) NOT NULL)WITH (MEMORY_OPTIMIZED = ON)

Memory for Table: Timestamps + Index Pointers + Row Data => 24 + (8+8+8+8) + (4+4+4+4+4+50+50+30+50) => 256 x 5000000 => 1.28GBMemory for Hash Indexes: Round Up Bucket Count x Index Pointer => 223 x 8 => 67,108,864 Bytes => 64MB x 3 => 192MBMemory for Non-Clustered Index: (Index Pointer + SUM(Key Column Data Type Size)) x Unique Rows => (8 + 4) x 5000000 => 57MB Memory for Row Versioning: (Longest Trans. Duration in Sec. x Peak No. of Row Updates & Deletes in Sec.) x Row Size

=> ( 1 x 10) x 256 => 2560 Bytes => 2560 x (0.3 x 5000000) => 3.66GB

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 12: SQL Server In-Memory Internals and Performance Tips

In-Memory Filegroup Configuration

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 13: SQL Server In-Memory Internals and Performance Tips

In-Memory Data & Delta File Population

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.

Page 14: SQL Server In-Memory Internals and Performance Tips

Questions and Answers

Copyrights © 2016 Fard Solutions Sdn Bhd, All rights reserved.