The speed of RAM!

I’ve been playing around with writing some data to RAM lately, and I’ve been hugely impressed.
Now, let’s start with the beginning: everybody knows RAM is faster than SSD, which is faster than spinning disk. Why was I so impressed with this test? Well simply, I’ve never considered actually writing files to RAM. I have addressed RAM by storing an object in RAM in a script/program, but never written a file there.
That changed today, and let me quickly share some results; compared to our 3 disk tiers in Azure.
Small sidenote: a RAMdisk is not something Azure specific; you could use it on every system. On Azure Linux VMs, the RAMdisk is mounted by default under /dev/shm, but you can enable it on any Linux machine (but not yet on WSL).

Results

My test itself was very basic, consisting of writing zeroes to disk:

sudo dd if=/dev/zero  of=/dev/shm/test1.img bs=16M count=64 oflag=dsync

RAMdisk

Temp drive

Premium SSD

Standard SSD

Standard HDD

Standard_D2s_v3

2.1GB/s

32.9MB/s

48.9MB/s

48.9MB/s

49.3MB/s

Standard_F2s_v2

2.7GB/s

32.9MB/s

48.9MB/s

48.8MB/s

45.9MB/s

Standard_B2s

1.8GB/s

24.6MB/s

22.4MB/s

24.1MB/s

24.6MB/s

I tried out the feature on multiple VM types and compared to different disks (each 127GB in size). Writing to RAM blows all the disks out of the water by a factor of at least 50x. There’s a noticeable difference between the Dv3 and Fv2 series; which I believe to be linked to a newer Intel chipset in the F-series. I was pleasantly surprised that a (fresh) B2s machine was also quiet fast in RAMdisk performance. I was a bit disappointed in the performance of the temp drive (it should have been faster according to my expectations).

Use cases

Now, when would you use RAMdisk? Well, let me start be telling you when NOT to use it. Never use it if you need to keep your data. If your machine reboots you will lose the data in RAM. That’s simple computer science, but don’t forget.
1 use case for RAMdisk is to temporarily save files that you use between programs.
I also thought about TempDB, but that would be a bad use case, because most of your DB is in RAM either way.
I had one use case myself where I wanted/needed to use RAM disk: generating random files and storing them into blob storage. We can pump data into blob at 20Gbps today (with higher throughput in preview up to 100Gbps – see the storage session at Ignite) – but if you generate files, you need to store them somewhere temporarily. A RAMdisk was a perfect location to store these files.

Conclusion

Writing files to RAM is at least 50x faster than writing them to SSD. You need to be careful when writing to RAM, as files are not persisted to disk and will be deleted upon reboot.

The code – for reference

#Just for reference, the commands I used to setup my environment/tests.
#prepare and mount disks
sudo fdisk /dev/sdc # also do or sdd sde
# lazy way to create new partition
# n <enter> <enter> <enter>
sudo mkfs.ext4 /dev/sdc1 #also do for sdd1 and sde1
sudo mount /dev/sdc1 /mnt/premium
sudo mount /dev/sdd1 /mnt/stdssd
sudo mount /dev/sde1 /mnt/stdhdd
#Do actual tests
echo "RAMDISK"
sudo dd if=/dev/zero  of=/dev/shm/test1.img bs=16M count=64 oflag=dsync
echo "TEMP"
sudo dd if=/dev/zero  of=/mnt/resource/test1.img bs=16M count=64 oflag=dsync
echo "PREMIUM"
sudo dd if=/dev/zero  of=/mnt/premium/test1.img bs=16M count=64 oflag=dsync
echo "STDSSD"
sudo dd if=/dev/zero  of=/mnt/stdssd/test1.img bs=16M count=64 oflag=dsync
echo "STDHDD"
sudo dd if=/dev/zero  of=/mnt/stdhdd/test1.img bs=16M count=64 oflag=dsync

Leave a Reply