Merge remote-tracking branch 'refs/remotes/Microsoft/master' into json

This commit is contained in:
Jovan Popovic
2016-06-14 22:25:48 +02:00
53 changed files with 2004 additions and 2832 deletions
@@ -46,17 +46,18 @@ ALTER DATABASE CURRENT
ADD FILEGROUP ' + QUOTENAME(@MODName) + N' CONTAINS MEMORY_OPTIMIZED_DATA;';
EXECUTE (@SQL);
-- add container in the filegroup
IF NOT EXISTS (SELECT * FROM sys.database_files WHERE data_space_id IN (SELECT data_space_id FROM sys.filegroups WHERE type = N'FX'))
BEGIN
SET @SQL = N'
END;
-- add container in the filegroup
IF NOT EXISTS (SELECT * FROM sys.database_files WHERE data_space_id IN (SELECT data_space_id FROM sys.filegroups WHERE type = N'FX'))
BEGIN
SET @SQL = N'
ALTER DATABASE CURRENT
ADD FILE (name = N''' + @MODName + ''', filename = '''
+ @MemoryOptimizedFilegroupFolder + N''')
TO FILEGROUP ' + QUOTENAME(@MODName);
EXECUTE (@SQL);
END
END;
EXECUTE (@SQL);
END
END
-- 3. set compat level to 130 if it is lower
@@ -1,8 +1,21 @@
# In-Memory OLTP Performance Improvement Sample
# In-Memory OLTP Performance Improvement Sample
This Windows Forms sample application built on .NET Framework 4.6 demonstrates the performance benefits of using SQL Server memory optimized tables and native compiled stored procedures. You can compare the performance before and after enabling In-Memory OLTP by observing the transactions/sec as well as the current CPU Usage and latches/sec.
![Alt text](Screenshots/1.png "Ticket Reservations")
<a name=about-this-sample></a>
## About this sample
<!-- Delete the ones that don't apply -->
* **Latest release:** [in-memory-oltp-perf-demo-v1.0](https://github.com/Microsoft/sql-server-samples/releases/tag/in-memory-oltp-demo-v1.0)
* **Applies to:** SQL Server 2014 (or higher), Azure SQL Database
* **Key features:** In-Memory OLTP
* **Workload:** OLTP
* **Programming Language:** T-SQL, C#
* **Authors:** Jos de Bruijn
![Alt text](/media/in-memory-oltp-performance.png "Ticket Reservations")
## Running this sample
1. Before you can run this sample, you must have the following perquisites:
@@ -1,34 +0,0 @@
** Warnings
User level transactions are not supported for memory optimized objects. You must disable the 'Include transactional
scripts' deployment option to successfully deploy changes to memory optimized objects.
** Highlights
Tables that will be rebuilt
None
Clustered indexes that will be dropped
[dbo].[sql_ts_th] on [dbo].[TicketReservationDetail]
Clustered indexes that will be created
None
Possible data issues
The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the
table have been redefined.
** User actions
Create
[mod] (Filegroup)
[dbo].[TicketReservationDetail] (Table)
[dbo].[InsertReservationDetails] (Procedure)
Drop
[dbo].[InsertReservationDetails] (Procedure)
[dbo].[sql_ts_th] (Primary Key)
[dbo].[TicketReservationDetail] (Table)
Alter
[dbo].[ReadMultipleReservations] (Procedure)
[dbo].[BatchInsertReservations] (Procedure)
** Supporting actions
Refresh
[dbo].[Demo_Reset] (Procedure)
The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the table have been redefined.
@@ -1,25 +0,0 @@
** Warnings
User level transactions are not supported for memory optimized objects. You must disable the 'Include transactional
scripts' deployment option to successfully deploy changes to memory optimized objects.
** Highlights
Tables that will be rebuilt
None
Clustered indexes that will be dropped
None
Clustered indexes that will be created
None
Possible data issues
None
** User actions
Drop
[dbo].[InsertReservationDetails] (Procedure)
Create
[dbo].[TicketReservationDetail] (Table)
[dbo].[InsertReservationDetails] (Procedure)
Alter
[dbo].[ReadMultipleReservations] (Procedure)
[dbo].[BatchInsertReservations] (Procedure)
** Supporting actions
@@ -1,258 +0,0 @@
/*
Deployment script for TicketReservations
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/
GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
GO
:setvar DatabaseName "TicketReservations"
:setvar DefaultFilePrefix "TicketReservations"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\"
:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\"
GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
BEGIN
PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
SET NOEXEC ON;
END
GO
PRINT N'Creating [mod]...';
GO
ALTER DATABASE [$(DatabaseName)]
ADD FILEGROUP [mod] CONTAINS MEMORY_OPTIMIZED_DATA;
GO
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [mod_4C0B6475], FILENAME = N'$(DefaultDataPath)$(DefaultFilePrefix)_mod_4C0B6475.mdf') TO FILEGROUP [mod];
GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET ANSI_NULLS ON,
ANSI_PADDING ON,
ANSI_WARNINGS ON,
ARITHABORT ON,
CONCAT_NULL_YIELDS_NULL ON,
QUOTED_IDENTIFIER ON,
ANSI_NULL_DEFAULT ON,
CURSOR_DEFAULT LOCAL
WITH ROLLBACK IMMEDIATE;
END
GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET PAGE_VERIFY NONE,
DISABLE_BROKER
WITH ROLLBACK IMMEDIATE;
END
GO
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT = ON
WITH ROLLBACK IMMEDIATE;
END
GO
USE [$(DatabaseName)];
GO
/*
The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the table have been redefined.
*/
IF EXISTS (select top 1 1 from [dbo].[TicketReservationDetail])
RAISERROR (N'Rows were detected. The schema update is terminating because data loss might occur.', 16, 127) WITH NOWAIT
GO
PRINT N'Dropping [dbo].[InsertReservationDetails]...';
GO
DROP PROCEDURE [dbo].[InsertReservationDetails];
GO
PRINT N'Dropping [dbo].[sql_ts_th]...';
GO
ALTER TABLE [dbo].[TicketReservationDetail] DROP CONSTRAINT [sql_ts_th];
GO
PRINT N'Dropping [dbo].[TicketReservationDetail]...';
GO
DROP TABLE [dbo].[TicketReservationDetail];
GO
PRINT N'Creating [dbo].[TicketReservationDetail]...';
GO
CREATE TABLE [dbo].[TicketReservationDetail] (
[TicketReservationID] BIGINT NOT NULL,
[TicketReservationDetailID] BIGINT IDENTITY (1, 1) NOT NULL,
[Quantity] INT NOT NULL,
[FlightID] INT NOT NULL,
[Comment] NVARCHAR (1000) NULL,
CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY NONCLUSTERED ([TicketReservationDetailID] ASC)
)
WITH (MEMORY_OPTIMIZED = ON);
GO
PRINT N'Creating [dbo].[InsertReservationDetails]...';
GO
/*
CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int)
AS
BEGIN
DECLARE @loop int = 0;
WHILE (@loop < @LineCount)
BEGIN
INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment)
VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment);
SET @loop += 1;
END
END
*/
-- natively compiled version of the stored procedure:
CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int)
WITH NATIVE_COMPILATION, SCHEMABINDING
as
BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English')
DECLARE @loop int = 0;
while (@loop < @LineCount)
BEGIN
INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment)
VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment);
SET @loop += 1;
END
END
GO
PRINT N'Altering [dbo].[ReadMultipleReservations]...';
GO
ALTER PROCEDURE ReadMultipleReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int)
AS
BEGIN
DECLARE @tranCount int = 0;
DECLARE @CurrentSeq int = 0;
DECLARE @Sum int = 0;
DECLARE @loop int = 0;
WHILE (@tranCount < @ServerTransactions)
BEGIN
BEGIN TRY
SELECT @CurrentSeq = RAND() * IDENT_CURRENT(N'dbo.TicketReservationDetail')
SET @loop = 0
BEGIN TRAN
WHILE (@loop < @RowsPerTransaction)
BEGIN
SELECT @Sum += FlightID from dbo.TicketReservationDetail where TicketReservationDetailID = @CurrentSeq - @loop;
SET @loop += 1;
END
COMMIT TRAN
END TRY
BEGIN CATCH
IF XACT_STATE() = -1
ROLLBACK TRAN
;THROW
END CATCH
SET @tranCount += 1;
END
END
GO
PRINT N'Altering [dbo].[BatchInsertReservations]...';
GO
-- helper stored procedure to
ALTER PROCEDURE BatchInsertReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int)
AS
BEGIN
DECLARE @tranCount int = 0;
DECLARE @TS Datetime2;
DECLARE @Char_TS NVARCHAR(23);
DECLARE @CurrentSeq int = 0;
SET @TS = SYSDATETIME();
SET @Char_TS = CAST(@TS AS NVARCHAR(23));
WHILE (@tranCount < @ServerTransactions)
BEGIN
BEGIN TRY
BEGIN TRAN
SET @CurrentSeq = NEXT VALUE FOR TicketReservationSequence ;
EXEC InsertReservationDetails @CurrentSeq, @RowsPerTransaction, @Char_TS, @ThreadID;
COMMIT TRAN
END TRY
BEGIN CATCH
IF XACT_STATE() = -1
ROLLBACK TRAN
;THROW
END CATCH
SET @tranCount += 1;
END
END
GO
PRINT N'Refreshing [dbo].[Demo_Reset]...';
GO
EXECUTE sp_refreshsqlmodule N'[dbo].[Demo_Reset]';
GO
PRINT N'Update complete.';
GO
@@ -1,171 +0,0 @@
/*
Deployment script for TicketReservations
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/
GO
SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
GO
:setvar DatabaseName "TicketReservations"
:setvar DefaultFilePrefix "TicketReservations"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\"
:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\"
GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
BEGIN
PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
SET NOEXEC ON;
END
GO
USE [$(DatabaseName)];
GO
PRINT N'Dropping [dbo].[InsertReservationDetails]...';
GO
DROP PROCEDURE [dbo].[InsertReservationDetails];
GO
PRINT N'Creating [dbo].[TicketReservationDetail]...';
GO
CREATE TABLE [dbo].[TicketReservationDetail] (
[TicketReservationID] BIGINT NOT NULL,
[TicketReservationDetailID] BIGINT IDENTITY (1, 1) NOT NULL,
[Quantity] INT NOT NULL,
[FlightID] INT NOT NULL,
[Comment] NVARCHAR (1000) NULL,
CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY NONCLUSTERED ([TicketReservationDetailID] ASC)
)
WITH (MEMORY_OPTIMIZED = ON);
GO
PRINT N'Creating [dbo].[InsertReservationDetails]...';
GO
/*
CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int)
AS
BEGIN
DECLARE @loop int = 0;
WHILE (@loop < @LineCount)
BEGIN
INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment)
VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment);
SET @loop += 1;
END
END
*/
-- natively compiled version of the stored procedure:
CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int)
WITH NATIVE_COMPILATION, SCHEMABINDING
as
BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English')
DECLARE @loop int = 0;
while (@loop < @LineCount)
BEGIN
INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment)
VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment);
SET @loop += 1;
END
END
GO
PRINT N'Altering [dbo].[ReadMultipleReservations]...';
GO
ALTER PROCEDURE ReadMultipleReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int)
AS
BEGIN
DECLARE @tranCount int = 0;
DECLARE @CurrentSeq int = 0;
DECLARE @Sum int = 0;
DECLARE @loop int = 0;
WHILE (@tranCount < @ServerTransactions)
BEGIN
BEGIN TRY
SELECT @CurrentSeq = RAND() * IDENT_CURRENT(N'dbo.TicketReservationDetail')
SET @loop = 0
BEGIN TRAN
WHILE (@loop < @RowsPerTransaction)
BEGIN
SELECT @Sum += FlightID from dbo.TicketReservationDetail where TicketReservationDetailID = @CurrentSeq - @loop;
SET @loop += 1;
END
COMMIT TRAN
END TRY
BEGIN CATCH
IF XACT_STATE() = -1
ROLLBACK TRAN
;THROW
END CATCH
SET @tranCount += 1;
END
END
GO
PRINT N'Altering [dbo].[BatchInsertReservations]...';
GO
-- helper stored procedure to
ALTER PROCEDURE BatchInsertReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int)
AS
BEGIN
DECLARE @tranCount int = 0;
DECLARE @TS Datetime2;
DECLARE @Char_TS NVARCHAR(23);
DECLARE @CurrentSeq int = 0;
SET @TS = SYSDATETIME();
SET @Char_TS = CAST(@TS AS NVARCHAR(23));
WHILE (@tranCount < @ServerTransactions)
BEGIN
BEGIN TRY
BEGIN TRAN
SET @CurrentSeq = NEXT VALUE FOR TicketReservationSequence ;
EXEC InsertReservationDetails @CurrentSeq, @RowsPerTransaction, @Char_TS, @ThreadID;
COMMIT TRAN
END TRY
BEGIN CATCH
IF XACT_STATE() = -1
ROLLBACK TRAN
;THROW
END CATCH
SET @tranCount += 1;
END
END
GO
PRINT N'Update complete.';
GO
@@ -1,4 +1,4 @@
-- helper stored procedure to
-- helper stored procedure to batch reservations
CREATE PROCEDURE BatchInsertReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int)
AS