SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

SQL Server on steroids with RAM disk

I’ve faced pretty common situation recently – you need to work with huge data during development/testing. It’s good if you have option how to access large data volumes XXX% faster on your laptop. I can imagine many other scenarios when you need to work with hundreds thousands of records on your development machine. Great solution for that is to use RAM disk and store your database on it.

According to wikipedia RAM Disk “is a block of RAM (primary storage or volatile memory) that a computer’s software is treating as if the memory were a disk drive (secondary storage).”. It does what it does so you can slice part of your memory and create logical disk drive which is treated as drive on system level (by low-level drivers). SQL Server doesn’t care that this “disk” was created as part of your memory.

I used this tool to create RAM disk. It’s commercial but more stable than some free alternatives (I am using it also Visual Studio development).

This code performs simple 100k insert, I ran it on database stored on SSD disk at first, than on database stored on RAM disk (see results below):

-- create database on physical drive c:\ with default setting
( NAME = N'TestPerformance', FILENAME = N'C:\Sql Databases\TestPerformance.mdf' , SIZE = 4352KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
( NAME = N'TestPerformance_log', FILENAME = N'C:\Sql Databases\TestPerformance_log.LDF' , SIZE = 576KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
-- create database on ramdisk (drive L:\) with default setting
CREATE DATABASE [TestPerformanceRamdisk] ON  PRIMARY
( NAME = N'TestPerformanceRamdisk', FILENAME = N'L:\TestPerformanceRamdisk.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
( NAME = N'TestPerformanceRamdisk_log', FILENAME = N'L:\TestPerformanceRamdisk_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

-- create simple test tables in both databases
CREATE TABLE TestPerformance..TestInsert (testColumn UNIQUEIDENTIFIER)
CREATE TABLE TestPerformanceRamDisk..TestInsert (testColumn UNIQUEIDENTIFIER)

-- run this script on both databases and compare time
DECLARE @i INT = 100000

WHILE @i > 0

    INSERT INTO TestInsert
        VALUES (NEWID())

    SET @i -= 1

SET @end = GETDATE()
SELECT CONVERT (TIME, @end - @start)

Results are nice.
For SSD version, it was (~20s):

… for RAM disk version, it was (~7s):

RAM disk version is ~300% faster which is not negligible. Using RAM disk needn’t to be an option only for development machines. You can use RAM disk even for production to hold TEMPDB database (or any other treated as non-critical for persistence). Tony Rogerson’s wrote about this here.

Jakub Dvorak @ www.sqltreeo.com


Posted by Jason Brimhall on 5 July 2011

jealously slobbering

Posted by Jakub Dvorak on 5 July 2011

:) You can try this free altetmative, but it brought me blue screen couple of times (which might be only on my computer).  memory.dataram.com/.../ramdisk

Leave a Comment

Please register or log in to leave a comment.