<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>JJB Blog &#187; TDD</title> <atom:link href="http://blog.johnjosephbachir.org/tag/tdd/feed/" rel="self" type="application/rss+xml" /><link>http://blog.johnjosephbachir.org</link> <description></description> <lastBuildDate>Sat, 03 Jul 2010 21:41:47 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>How to use a RAM / memory disk for MySQL in Rails</title><link>http://blog.johnjosephbachir.org/2007/09/29/how-to-use-a-ram-memory-disk-for-mysql-in-rails/</link> <comments>http://blog.johnjosephbachir.org/2007/09/29/how-to-use-a-ram-memory-disk-for-mysql-in-rails/#comments</comments> <pubDate>Sat, 29 Sep 2007 20:53:45 +0000</pubDate> <dc:creator>John</dc:creator> <category><![CDATA[general]]></category> <category><![CDATA[disk]]></category> <category><![CDATA[functional]]></category> <category><![CDATA[memory]]></category> <category><![CDATA[memorydisk]]></category> <category><![CDATA[rails]]></category> <category><![CDATA[ram]]></category> <category><![CDATA[ramdisk]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[rubyonrails]]></category> <category><![CDATA[TDD]]></category> <category><![CDATA[tests]]></category> <category><![CDATA[unit]]></category> <category><![CDATA[unittests]]></category><guid isPermaLink="false">http://blog.johnjosephbachir.org/2007/09/29/how-to-use-a-ram-memory-disk-for-mysql-in-rails/</guid> <description><![CDATA[I wanted to use a RAM disk for my MySQL data files when running my tests for a Rails project. I succeeded, but it only cut 2 seconds off of my ~30 second test suite for my functional tests, and didn't cut any time off of my unit tests. But nevertheless, here is how I [...]]]></description> <content:encoded><![CDATA[<p>I wanted to use a RAM disk for my MySQL data files when running my tests for a Rails project. I succeeded, but it only cut 2 seconds off of my ~30 second test suite for my functional tests, and didn't cut any time off of my unit tests. But nevertheless, here is how I achieved this, in case it is useful to others. All of this is on OS X, using MySQL 5 from Macports.</p><p>What we are doing is creating a RAM disk, and then creating a seperate MySQL instance that stores its data on that RAM disk.</p><div class="igBar"><span id="lbash-2"><a href="#" onclick="javascript:showPlainTxt('bash-2'); return false;">[click here for plain text]</a></span></div><div class="syntax_hilite"><span class="langName">BASH:</span><div id="bash-2"><div class="bash" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># Create the RAM disk</span></div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">hdid -nomount ram://<span style="color: #000000;color:#800000;">52428800</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">newfs_hfs /dev/disk1</div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> /tmp/ramdisk1</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #c20cb9; font-weight: bold;">mount</span> -t hfs /dev/disk1 /tmp/ramdisk1</div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># Initialize the MySQL environment</span></div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql_install_db5 --<span style="color: #007800;">datadir=</span>/tmp/ramdisk1</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># Start the MySQL server</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">/opt/<span style="color: #7a0874; font-weight: bold;">local</span>/libexec/mysqld --<span style="color: #007800;">basedir=</span>/opt/<span style="color: #7a0874; font-weight: bold;">local</span> --<span style="color: #007800;">datadir=</span>/tmp/ramdisk1 &nbsp;--pid-<span style="color: #007800;">file=</span>/tmp/mysql_memory_localhost.pid --<span style="color: #007800;">port=</span><span style="color: #000000;color:#800000;">10000</span> --<span style="color: #007800;">socket=</span>/tmp/mysql_memory.sock</div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># Create your <span style="color: #7a0874; font-weight: bold;">test</span> database</span></div></li><li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysqladmin5 --<span style="color: #007800;">socket=</span>/tmp/mysql_memory.sock -uroot create projectname_test</div></li></ol></div></div></div><p></p><p>Now in your <strong>database.yml</strong> file, add <code>socket: /tmp/mysql_memory.sock</code> to the test database configuration.</p><p>(thanks to <a href="http://osxdaily.com/2007/03/23/create-a-ram-disk-in-mac-os-x/">this tutorial</a> for how-to create a RAM disk in OS X)</p><p class="akst_link"><a href="http://blog.johnjosephbachir.org/?p=494&amp;akst_action=share-this"  title="Email, post to del.icio.us, etc." id="akst_link_494" class="akst_share_link" rel="noindex nofollow">Share</a></p>]]></content:encoded> <wfw:commentRss>http://blog.johnjosephbachir.org/2007/09/29/how-to-use-a-ram-memory-disk-for-mysql-in-rails/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 25/31 queries in 0.040 seconds using disk

Served from: blog.johnjosephbachir.org @ 2010-09-10 19:45:03 -->