{"id":129,"date":"2018-10-10T18:22:50","date_gmt":"2018-10-10T18:22:50","guid":{"rendered":"https:\/\/nillsf.wordpress.com\/?p=129"},"modified":"2018-10-10T18:22:50","modified_gmt":"2018-10-10T18:22:50","slug":"the-speed-of-ram","status":"publish","type":"post","link":"https:\/\/nillsf.com\/index.php\/2018\/10\/10\/the-speed-of-ram\/","title":{"rendered":"The speed of RAM!"},"content":{"rendered":"<p>I&#8217;ve been playing around with writing some data to RAM lately, and I&#8217;ve been hugely impressed.<br \/>\nNow, let&#8217;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&#8217;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.<br \/>\nThat changed today, and let me quickly share some results; compared to our 3 disk tiers in Azure.<br \/>\nSmall 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).<\/p>\n<h1>Results<\/h1>\n<p>My test itself was very basic, consisting of writing zeroes to disk:<\/p>\n<pre>sudo dd if=\/dev\/zero\u00a0 of=\/dev\/shm\/test1.img bs=16M count=64 oflag=dsync<\/pre>\n<div style=\"direction:ltr;\">\n<table  class=\" table table-hover\" style=\"direction:ltr;border-collapse:collapse;border:1pt solid #A3A3A3;\" title=\"\" border=\"1\" summary=\"\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"vertical-align:top;width:1.2888in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;\">\n<\/td>\n<td style=\"vertical-align:top;width:.7631in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">RAMdisk<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.9173in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Temp drive<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0534in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Premium SSD<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0472in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Standard SSD<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0131in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Standard HDD<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:1.3083in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Standard_D2s_v3<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.7437in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">2.1GB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.8979in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">32.9MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.034in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">48.9MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0277in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">48.9MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.909in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">49.3MB\/s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:1.2888in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Standard_F2s_v2<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.7437in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">2.7GB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.8979in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">32.9MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.034in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">48.9MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0277in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">48.8MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.909in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">45.9MB\/s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:1.2888in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">Standard_B2s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.7437in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">1.8GB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.8979in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">24.6MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.034in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">22.4MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:1.0277in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">24.1MB\/s<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:.909in;padding:4pt;border:1pt solid #A3A3A3;\">\n<p style=\"margin:0;font-family:Calibri;font-size:11pt;color:black;\">24.6MB\/s<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>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&#8217;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).<\/p>\n<h1>Use cases<\/h1>\n<p>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&#8217;s simple computer science, but don&#8217;t forget.<br \/>\n1 use case for RAMdisk is to temporarily save files that you use between programs.<br \/>\nI also thought about TempDB, but that would be a bad use case, because most of your DB is in RAM either way.<br \/>\nI 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 &#8211; see the storage session at Ignite) &#8211; but if you generate files, you need to store them somewhere temporarily. A RAMdisk was a perfect location to store these files.\n<\/p><\/div>\n<div><\/div>\n<h1>Conclusion<\/h1>\n<p>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.<\/p>\n<h1>The code &#8211; for reference<\/h1>\n<pre>#Just for reference, the commands I used to setup my environment\/tests.\n#prepare and mount disks\nsudo fdisk \/dev\/sdc # also do or sdd sde\n# lazy way to create new partition\n# n &lt;enter&gt; &lt;enter&gt; &lt;enter&gt;\nsudo mkfs.ext4 \/dev\/sdc1 #also do for sdd1 and sde1\nsudo mount \/dev\/sdc1 \/mnt\/premium\nsudo mount \/dev\/sdd1 \/mnt\/stdssd\nsudo mount \/dev\/sde1 \/mnt\/stdhdd\n#Do actual tests\necho \"RAMDISK\"\nsudo dd if=\/dev\/zero\u00a0 of=\/dev\/shm\/test1.img bs=16M count=64 oflag=dsync\necho \"TEMP\"\nsudo dd if=\/dev\/zero\u00a0 of=\/mnt\/resource\/test1.img bs=16M count=64 oflag=dsync\necho \"PREMIUM\"\nsudo dd if=\/dev\/zero\u00a0 of=\/mnt\/premium\/test1.img bs=16M count=64 oflag=dsync\necho \"STDSSD\"\nsudo dd if=\/dev\/zero\u00a0 of=\/mnt\/stdssd\/test1.img bs=16M count=64 oflag=dsync\necho \"STDHDD\"\nsudo dd if=\/dev\/zero\u00a0 of=\/mnt\/stdhdd\/test1.img bs=16M count=64 oflag=dsync<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been playing around with writing some data to RAM lately, and I&#8217;ve been hugely impressed. Now, let&#8217;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&#8217;ve never considered actually writing files to RAM. I have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":0,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nillsf.com\/index.php\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}