| Basel SQL Server 2014: In- Memory OLTP Stéphane Haby - Stéphane Savorgnano Consultant dbi...

Post on 01-Apr-2015

215 views 0 download

transcript

| Basel

SQL Server 2014: In-Memory OLTPStéphane Haby - Stéphane SavorgnanoConsultantdbi services

Agenda

Agenda

IntroductionHow to process?Memory optimized objectsConcurrency controlDemoConclusion

| Basel

Introduction

Chapter 1/6

Introduction

Stéphane SavorgnanoConsultantMobile +41 79 870 54 62Stephane.savorgnano@dbi-services.com

Stéphane HabyDelivery ManagerSenior ConsultantMobile +41 79 103 89 60Stephane.haby@dbi-services.com

Introduction

dbi servicesExperts At Your Service 30 specialists in IT infrastructure Certified, experienced, passionate

Based In Switzerland 100% self-financed Swiss company More than CHF 3 mio. in sales

Leading In Infrastructure Services Over 70 customers in CH, D, & F 30 SLAs dbi FlexService signed

Introduction

Project HekatonDelivering the feature In-Memory OLTP Algorithms optimized for accessing in-memory data Optimistic concurrency control: eliminate logical locks due to automatic snapshot

isolation with multiple versioning Lock free and latch free structures to access dataStarted around 4 years ago

The goalBoost performance of OLTP workloads Using new memory optimized technology

Introduction

How?Take advantage of full memories and processor cores Hardware are more and more powerful

CPU with multiple cores RAM increase due to low price

Why?Stick to the market which wants Higher performance

More and more fast response (online betting, online credit-card transaction, online trading, …)

| Basel

How to process?

Chapter 2/6

How to process?

Find in your databasePerformance issues Tables with critical performances Stored Procedures

With complex logical calculations Huge tables crossover

Solve problemsCreation of a specific in-Memory FilegroupPut tables and Stored procedures with critical performances in-Memory

AdvantagesFast response(10x, 20x…)Access to those in-Memory objects is done as beforeCompletely integrated to SQL Server

| Basel

Memory Optimized Objects

Chapter 3/6

Filegroup

Memory Optimized Objects

New kind of filegroup have been created To contain memory optimized objects Filegroup Container is first similar to filestream

Memory Optimized ObjectsInternal representation

Tables and Indexes

Memory Optimized Objects

Tables and indexes can be created by script as usualA new type of index appear: Hash index It is a non clustered index Need the option bucket_count to know the size of the index (twice the size of the

rows expected)

Memory Optimized Objects

Table creationWhen the script is executed A CREATE TABLE DDL code is generated This CREATE TABLE DDL is transformed in a C program This C program is compiled A DLL is produced The DLL is loaded in memory

Files created for each table:

Memory Optimized ObjectsHash Indexes>Use Hash function(f)

>Maps randomly values to buckets

>Defined in the system

>Bucket_count>Number of slot in the hash

index>Array of 8-byte memory

pointers

4567

0123

Hash mapping(with Bucket_count = 8):

f(Yann)

f(Greg)f(Steph)

f(Audi)

f(Mercedes), f(VW)

Hash Collision

s

Memory Optimized Objects

40, ∞Step

hAudi

Timestamps

NameChain ptrs CarMaque

Hash index on CarMaque

Hash index on name

80, ∞ Greg Mercedes

f(Greg)

f(Steph)f(Audi)

f(Mercedes)

Memory Optimized Objects

40, ∞Step

hAudi

Timestamps

NameChain ptrs CarMaque

Hash index on CarMaque

Hash index on name

80, ∞ Greg Mercedes

f(Audi)90, ∞ Yann Audi

f(Yann)

T90: Insert(Yann, Audi)

Memory Optimized Objects

40, ∞Step

hAudi

Timestamps

NameChain ptrs CarMaque

Hash index on CarMaque

Hash index on name

80, ∞ Greg Mercedes

90, ∞ Yann Audi

T120: Delete(Greg, Mercedes)

80, 120

Memory Optimized Objects

40, ∞Step

hAudi

Timestamps

NameChain ptrs CarMaque

Hash index on CarMaque

Hash index on name

80, ∞ Greg Mercedes

90, ∞ Yann Audi

T180: Update(Yann, Audi) to (Yann, Mercedes)

80, 120

180, ∞ Yann Mercedes

90, 180

f(Yann)

f(Mercedes)

Memory Optimized Objects

40, ∞Step

hAudi

Timestamps

NameChain ptrs CarMaque

Hash index on CarMaque

Hash index on name

T220: Garbage collector80, ∞ Greg Mercedes80, 120

180, ∞ Yann Mercedes

90, ∞ Yann Audi90, 180

f(Yann)

f(Mercedes)

f(Audi)f(Steph)

Memory Optimized Objects

Limitations on tables for version CTP1No foreign key and check constraintsNo identity (now available with CTP2, just (1,1))Cannot alter table, need to drop and recreate the tableCannot add or remove an index, need to drop and recreate tableNo LOB(Large Object) like nvarchar(max)Max size for a row is 8060 bytes(optimized for in–memory)No DML TriggersNo XML or CLR data types

Stored Procedures

Memory Optimized Objects

Stored procedure can be created by script with special argumentsNo alter procedure possible, need to drop and recreate the procedure

Memory Optimized Objects

When the script is executed A CREATE PROC DDL code is generated The query is optimized A C program is generated for CREATE PROC DLL This C program is compiled A DLL is produced The DLL is loaded in memory

Files created for each Stored procedure(same files than for a table)

Memory Optimized ObjectsHow to work with in-Memory tablesT-SQL

>Possibility to access in the same script in-memory and disk based tables

>Less efficient>But all T-SQL Surface

When to use>Adhoc queries>Reporting queries>Migration queries

Natively compile Stored Procedures

>Cannot access disk tables, only in-memory tables

>Very efficient>Limited T-SQL Surface(or, outer

join…)

When to use>OLTP style operations>Critical performance operations

| Basel

Concurrency control

Chapter 4/6

Concurrency control

In-Memory table>Multi-version: each tables can

have multiple versions of each rows

>Transaction isolation level is snapshot based

>Transaction semantic is optimistic: always assume that a transaction is going to commit(no locks, no latches)

>Conflict detection to ensure isolation(no deadlocks)

Disk based table>Locking and blocking to

guaranty isolation(even with snapshot or read committed snapshot you use locking for write)

| Basel

Demo

Chapter 5/6

Demo

| Basel

Conclusion

Chapter 6/6

ConclusionNew memory optimized tables New hash indexesNew natively compiled stored proceduresBring best performanceMulti-versioned rows, snapshot based isolationOptimistics: no locking, conflict detection

T-SQL limitationsCannot alter in-memory tablesCannot alter natively compiled stored procedures

ConclusionSQL Server 2014 web sitehttp://www.microsoft.com/en-us/sqlserver/sql-server-2014.aspx

SQL Server 2014 CPT2 downloadhttp://technet.microsoft.com/fr-fr/evalcenter/dn205290.aspx

SQL Server 2014 CTP2: In-Memory Advisor for Tables and Stored http://www.dbi-services.com/index.php?option=com_easyblog&view=entry&id=277&Itemid=82

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a

commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a

commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.