<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Null Disquisition</title>
	
	<link>http://mumrah.net</link>
	<description>Python, AWS, Grad School, and your face</description>
	<lastBuildDate>Fri, 05 Mar 2010 00:23:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/NullDisquisition" /><feedburner:info uri="nulldisquisition" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>1080p content on your PS3</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/1KVh-nTtr8Y/</link>
		<comments>http://mumrah.net/2010/02/1080p-content-on-your-ps3/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 04:31:03 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=350</guid>
		<description><![CDATA[New toys bring new adventures. My awesome wife got me a PS3 for my birthday recently and I&#8217;ve been tinkering around with getting some non-Bluray HD content to play on it. My initial attempts to stream stuff over my network proved unsatisfying. Since the PS3 is only capable of 802.11g, I gave up on the [...]]]></description>
			<content:encoded><![CDATA[<p>New toys bring new adventures. My awesome wife got me a PS3 for my birthday recently and I&#8217;ve been tinkering around with getting some non-Bluray HD content to play on it. My initial attempts to stream stuff over my network proved unsatisfying. Since the PS3 is only capable of 802.11g, I gave up on the high bitrate stuff (it&#8217;s perfectly capable of DVD quality content (1.5~2.5 Mb/s).</p>

<p>Software used (on Mac OS X 10.5):</p>

<ul>
<li><a href="http://www.smlabs.net/tsmuxer_en.html" title="tsMuxer website">tsMuxer</a></li>
<li>Disk Utility</li>
<li>newfs_udf</li>
<li>hdiutil</li>
</ul>

<p>Hardware used:</p>

<ul>
<li>Macbook Pro</li>
<li>Blank CD/DVD Media</li>
<li>PS3</li>
</ul>

<p>Files used:
* MKV file with AC3 audio stream and H264 video stream</p>

<p>Attempt 1 (<strong>successful</strong>): Load the MKV with tsMuxerGUI, select M2TS muxing. If the video profile is above 4.1, lower it to 4.1 (as the PS3 cannot support higher than an H264 level 4.1). Generate the m2ts and meta file, burn them both to a CD/DVD. This will be readable by the PS3 as a data disk &#8211; it will not autoplay, but you can access it and play it. To me, this is not an ideal solution as it does not support menus, chapters, or seeking.</p>

<p>Attempt 2 (<strong>unsuccessful</strong>): Same deal as before, but select &#8220;AVCHD disk&#8221;. This option will create a BD friendly file structure (folders named BDMV and CERTIFICATE). The trick here is to burn the disk as UDF 2.5 (this is not super easy on OS X or Linux). I wasted many CDs trying to regular ISO9660. Following the instructions <a href="http://www.videohelp.com/forum/archive/how-to-burn-avchd-on-dvd-r-in-high-definition-for-br-set-top-playback-t350375.html" title="about halfway down">here</a>, you must create the image and format it as UDF 2.5.</p>

<pre><code>dd if=/dev/zero of=myfile.img bs=1k count=716800
newfs_udf -r 2.5 myfile.img -v volume_label
hdiutil mount -nobrowse myfile.img
cp -R /path/to/avcdh-files/ /Volume/volume_label/
hdiutil unmount /Volume/volume_label
</code></pre>

<p><br/>
In plain-speak, create an empty (large) image, format it to UDF 2.5, mount it, copy the BD-compatible files into the volume, and unmount. You then use Disk Utility to burn the resulting image. No success here, but at this point I was so close, I could taste it.</p>

<p>Attempt 3 (<strong>successful</strong>): <em>Identical</em> procedure as Attempt 2, with one important exception &#8211; the image you create with <code>dd</code> must be sized in even increments of 1GB &#8211; that is, count==N&#42;1024&#42;1024.</p>

<p>A few things to try next:</p>

<ul>
<li>Menus</li>
<li>DTS audio stream</li>
<li>Subtitles</li>
</ul>

<p>Anyone wanting to test this out with a super high quality 1080p rip, I recommend <a href="http://www.bigbuckbunny.org/index.php/download/" title="Big Buck Bunny - Open Movie Project">Big Buck Bunny</a>. You&#8217;ll need Handbrake to convert it to a compatible container format if you download the AVI (tsMuxer doesn&#8217;t like AVIs).</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/1KVh-nTtr8Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2010/02/1080p-content-on-your-ps3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2010/02/1080p-content-on-your-ps3/</feedburner:origLink></item>
		<item>
		<title>Making Python’s pickle safe(r)</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/jX-bsTkg8hU/</link>
		<comments>http://mumrah.net/2009/09/making-pythons-pickle-safer/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 16:24:22 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=329</guid>
		<description><![CDATA[Securing pickled data with a HMAC SHA256 signature]]></description>
			<content:encoded><![CDATA[<p><img class="alignright s3-img" style="border: 0px initial initial;margin-left:10px;margin-bottom:10px;" src="http://mumrah-dot-net.s3.amazonaws.com/terrified-pickles_LRG.jpg" border="0" alt="Scared Pickles" width="137" height="181" /> Everyone loves pickle, I mean, what&#8217;s not to love. Super fast object serialization (via cPickle). However, there are some legitimate concerns regarding the security of pickle &#8211; specifically the load/loads method. The basic problem is, if you try to unpickle untrusted data, you are liable to create some objects that can do nasty things (<a title="Importing OS with Pickle" href="http://docs.python.org/3.1/library/pickle.html#restricting-globals" target="_blank">like make system calls</a>). Python even gives us a nice warning right in the docs</p>

<blockquote><strong>Warning</strong>
<em>pickle</em> module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.</blockquote>

<p><br/></p>

<p>Now there are plenty of things you can do to improve the security of the unpickling process. Python lets you subclass pickle.Unpickler to give the user finer grained control over what gets unpickled. This is a fine approach (<a title="Example of a safer Unpickler class" href="http://nadiana.com/python-pickle-insecure" target="_blank">a nice example here</a>), and will work for most, but I will give my take on the issue.</p>

<p>For most of the applications I write that use pickle, I&#8217;m just looking for a way to store arbitrary Python data as a string. One example might be storing small data objects on S3, or perhaps implementing user sessions for a webapp. Either way, I <em>should</em> be able to trust my own data for unpickling, but it&#8217;s always best to be double-extra-sure when dealing with something where you can blindly execute arbitrary bits of code (think, the evil eval method).</p>

<p>So, for my case, I simply want to verify that the pickled data I stored is coming back to me unmodified. My solution: sign the pickled data. Using the same signing method as AWS, I present the following:
<pre class="python" name="code">import hmac
import hashlib
import base64
from cPickle import dumps
 # The unsigned pickled data
string_to_sign = dumps({'foo':"bar",'spam':"eggs",'the answer':42})
 # The signature object
signature = hmac.HMAC(key="my application's super secret key",
    msg= string_to_sign, digestmod=hashlib.sha256)
 # The signed string: store this
signed_string = string_to_sign + base64.encodestring(signature.digest())</pre>
Now you have your pickled data as the first part of the string with the last 45 characters being the signature. The key for HMAC signing is specific to your application, so if someone gets access to your pickled data and tries to mess with it and resign it, it won&#8217;t work. Here&#8217;s the unpickling process:
<pre class="python" name="code">import hmac
import hashlib
import base64
from cPickle import loads
 # Break up the signed string into message and signature
signature = signed_string[-45:]
message = signed_string[:-45]
 # Calculate the signature of the message
msg_sig = hmac.HMAC(key="my application's super secret key",
    msg= message, digestmod=hashlib.sha256)
 # See that it matches the given signature
assert base64.encodestring(msg_sig.digest()) == signature</pre>
-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/jX-bsTkg8hU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/09/making-pythons-pickle-safer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/09/making-pythons-pickle-safer/</feedburner:origLink></item>
		<item>
		<title>API Functional Testing with Python</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/y_m0Uc1KU4o/</link>
		<comments>http://mumrah.net/2009/07/api-functional-testing-with-python/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 22:00:56 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[functional testing]]></category>
		<category><![CDATA[py.test]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=285</guid>
		<description><![CDATA[Recently, at work we have written a totally badass XML API for clients to interface with our data (sorry no public side yet). After some gentle reassuring (and some not-so-gentle arm twisting), I convinced my boss-man we could do this in Python with AWS on the back-end. We settled on the Turbogears 2.0 meta-framework using [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a href="http://loud3r.com" target="_blank" title="Loud3r">at work</a> we have written a totally badass XML API for clients to interface with our data (sorry no public side yet). After some gentle reassuring (and some not-so-gentle arm twisting), I convinced my boss-man we could do this in Python with AWS on the back-end. We settled on the Turbogears 2.0 meta-framework using Amazon S3/SimpleDB. The whole experience was very educational for many reasons &#8211; one, we had never using something besides MySQL for a data store, two, we had never used a Python framework before, and three, we had never really developed an app with a proper set of tests. That final point, testing, is the subject of this entry.</p>

<p><a href="http://codespeak.net/py/dist/test/test.html" title="[test]" target="_blank">Py.Test</a>, from the vaingloriously-named &#8220;py&#8221; module, is my unit testing framework of choice (I have <a href="http://mumrah.net/2009/02/python-unit-testing-super-fun-time/" title="Python unit testing super fun time" target="_self">written about it before</a>). It provides a convenient way to collect tests and to write generative tests (which are super useful) for unit testing. After getting a few sets of unit tests rolled out for our API, we recognized that we would need some higher level tests &#8211; so called functional, or acceptance tests.</p>

<h3>Functional Tests</h3>

<p>Functional tests describe high-level tests that rely on the interaction of many components of the system, whereas a unit test will only test smaller, lower level components. For example, one (very high-level) functional test for an XML API would be to see that the resulting XML is well-formed. The well-formedness of an XML response from an API request is dependent on several components of the system. It requires proper request parsing, validation, error handling, template rendering, et al. A more typical test might be to see that the number of items returned by the API does not exceed a user-provided maximum, i.e., if the user requests http://api.example.com/?[request params]&amp;max_count=10, no more than 10 results are shown.</p>

<p>Now, how to go about running these tests. The number of functional testing frameworks is too great to mention (<a href="http://www.opensourcetesting.org/functional.php" target="_blank" title="Exhaustive list of functional testing frameworks">here&#8217;s a bunch</a>), but one that is well known and widely used is Selenium. It is written in Java and can do some pretty fancy stuff. However, one big drawback of Selenium is it&#8217;s weight. It&#8217;s <em>heavy</em> &#8211; it is Java after all, and requires a client server (whether you sacrifice your own cycles or a remote server). For the simple functional tests we were writing, it was completely overkill. After searching around for a Python functional testing framework (or at least something lighter than Selenium), it occurred to me that I could just use the test-collecting abilities of Py.Test plus some additional libraries. And that&#8217;s what we did.</p>

<h3>Bottom Line</h3>

<p>Mix together <a href="http://pyxml.sourceforge.net/topics/" target="_blank" title="PyXML">PyXML</a>, Urllib2, and Py.Test and you have a pretty powerful (and portable) testing suite in Python. PyXML extends the built-in &#8216;xml&#8217; module with some really nice packages including an XPath parser which I love.</p>

<h3>Exempli Gratia</h3>

<p>Consider an API that has a &#8220;users&#8221; noun, and just one verb &#8220;show&#8221;. We will allow one optional parameter <em>order_by</em> and one required parameter <em>max_count</em>. An valid URL would look like http://api.example.com/users/show?max_count=10&amp;order_by=date.</p>

<p>We&#8217;ll start by creating the class that will contain the tests, and writing a function to get an XML doc given some url parameters.
<pre name="code" class="python">
import urllib2
from collections import defaultdict
from xml.dom import minidom
from xml import xpath
class TestUserNoun:
    def get_xml_doc(self,url_params):
        url = "http://api.example.com/users/show?"
        url += "max_count=%(max_count)s&amp;order_by=%(order_by)s"
        url_p = urllib2.urlopen( url % defaultdict(str,url_params) )
        doc = minidom.parseString( url_p.read() )
        url_p.close()
        return doc
</pre>
N.B., you can create a specific User-Agent with urllib2 if so desired, and defaultdict is used so we don&#8217;t have to check if the incoming dict (url_params) has everything we need for the url string.</p>

<p>Now we can start writing some tests
<pre name="code" class="python">
class TestUserNoun:
    ...
    def test_user_count(self):
        # Test several values of max_count
        counts = (5,10,15,20)
        def count_users(n):
            # Test that the number of results returned is less than or equal to n
            doc = self.get_xml_doc({'max_count':n})
            user_count = len( xpath.Evaluate('/xpath/expr',doc.documentElement) )
            assert user_count &lt;= n
        for c in counts:
            yield count_users,c
    def test_order_by_date(self):
        # See that each item is older than the previous one
        doc = self.get_xml_doc({'max_count':10,'order_by':"date"})
        items = xpath.Evaluate('/xpath/expr',doc.documentElement)
        # Get the date of the first item
        last_date = xpath.Evaluate('@date_attr',items[0])
        # Compare the date of each item to the previous one
        for item,i in zip(items[1:],range(len(items[1:]))):
            item_date = xpath.Evaluate('@date_attr',item)
            assert item_date &lt;= last_date
            last_date = item_date
</pre>
And you get the idea &#8211; one can write tests ad nauseum (although I&#8217;m not sure if there&#8217;s such a thing as too many tests). Of course neither of these tests will work since the XPath expressions are not valid &#8211; I didn&#8217;t really feel like spelling out a whole XML schema just for this example. There are plenty of good XPath tutorials out there. The basic idea here is you want to test all of your request parameters for the API to see a number of things:</p>

<ul>
<li>Does the controller handle the requests properly? What about missing/extra parameters?</li>
<li>Are errors handled properly?</li>
<li>Is the resulting XML valid? This is implicitly done by parsing the XML document</li>
<li>Does the resulting data correspond to the request parameters? This one will require the most tests to be written &#8211; don&#8217;t forget about generative tests!</li>
</ul>

<p>A powerful test suite means a robust application. When you have a nice set of tests, you can push your code with confidence &#8211; and believe me, that is a very rewarding and relieving feeling. Writing this API has been an extremely rewarding experience, and probably the most educational thing I&#8217;ve done programming-wise since I wrote a cross-browser javascript event library like 5 years ago.</p>

<p>So go forth, programmer &#8211; embrace testing and empower yourself.</p>

<p>-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/y_m0Uc1KU4o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/07/api-functional-testing-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/07/api-functional-testing-with-python/</feedburner:origLink></item>
		<item>
		<title>Weekend Project – CloudCached</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/XbW-f94I3YA/</link>
		<comments>http://mumrah.net/2009/06/weekend-project-cloudcached/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 20:34:15 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://mumrah.net/2009/06/weekend-project-cloudcached/</guid>
		<description><![CDATA[A friend and I have been bouncing around the idea of a caching system that ran on Amazon&#8217;s cloud for a while now. Basically something like memcached, but without the (very real) limitations of physical memory or the need of a whole server. Sure, it&#8217;s hard to beat the speed of memory-level read access, but [...]]]></description>
			<content:encoded><![CDATA[<p>A friend and I have been bouncing around the idea of a caching system that ran on Amazon&#8217;s cloud for a while now. Basically something like memcached, but without the (very real) limitations of physical memory or the need of a whole server. Sure, it&#8217;s hard to beat the speed of memory-level read access, but I think the appeal of a distributed, <a href="http://aws.amazon.com/s3/#functionality" title="Max 5GB per item" target="_blank">limitless</a> cache might outweigh the slowdown.</p>

<h3>Idea</h3>

<p>Provide an interface for storing/retrieving serialized data on S3</p>

<p>Pretty simple idea, pretty simple implementation. Thanks to the S3 interface provided by <a href="http://code.google.com/p/boto/" title="Boto rocks!">Boto</a>, things were a lot easier. I&#8217;m going to keep this open source under the MIT license. You can check out the code on <a href="http://github.com/mumrah/cloudcached/tree/master" title="CloudCached on GitHub">GitHub repository</a> &#8211; please feel free to fork, improve, submit, etc.</p>

<h3>Overview</h3>

<p>A quick walkthrough of the code will reveal truly how simple this is. The Client class provides basic CRUD methods for interfacing with S3: <strong>put</strong>, <strong>get</strong>, <strong>update</strong>, <strong>delete</strong>. The put and update methods store a timestamp as the &#8220;expires&#8221; header for the file to keep track of cache expiration. Also these two methods write a &#8220;type&#8221; header to the meta-data so CloudCached knows how to de-serialize the file. 
<pre name="code" class="python">
class Client:
"Here's the class schema"
    def get(self, key)
    def put(self, key, value, time_to_expire=3600, replace=False)
    def update(self, key, value, time_to_expire=3600)
    def delete(self, key)
</pre><br />
There are 6 basic data types used in this code for serializing any bit of python data: basestring (for str and unicode), int (for int and long), complex, float, and other. The other data type represents anything that is not a base type in Python. These &#8220;other&#8221; types get pickled while everything else just gets str&#8217;d.</p>

<p>The put method checks the md5sum to make sure everything went through cleanly (maybe a bit costly, but worth it in my opinion). cPickle is used in favor of pickle for obvious reasons (it&#8217;s much faster).</p>

<h3>Results</h3>

<p>Some very early tests show that this might just be usable. 
<pre name="code" class="python">
    CloudCached Benchmarks (10 runs)
    --------------------------------------------------------
    Test                 |  Average (s)     | Total (s)<br />
    --------------------------------------------------------
    GET integer          |  0.0283360004425 | 0.283360004425
    GET string (32 byte) |  0.0315794944763 | 0.315794944763
    GET string (512KB)   |  0.1265994787220 | 1.265994787220
    PUT integer          |  0.0650457143784 | 0.650457143784
    PUT string (32 byte) |  0.0563205003738 | 0.563205003738
    PUT string (512KB)   |  0.1773290872570 | 1.773290872570
    --------------------------------------------------------
</pre></p>

<h3>Advantages</h3>

<ul>
<li>Highly distributed. S3 data is distributed across multiple availability zones and could therefor be utilized by an application running across multiple availability zones.</li>
<li>No size limit. Unlike the physical limitations of a memcached machine (or cluster of memcached machines), S3 does not have limits on the number of files (caches) you can store. Also, with S3, you can write files from 1 byte to 5 GB (although I think a 5GB cache file would defeat the purpose).</li>
<li>Parallel read access. If applicable to the application, cache reads can be largely parallelized which could potentially give linear speedup to the cache loading.</li>
<li>No server necessary. Since the application is reading and writing directly to S3, there is no need to a &#8220;cache server&#8221;. This could lead to a great deal of savings for people running multiple memcached machines. Memcached servers typically have a large memory capacity which means a m1.xlarge or c1.xlarge EC2 instance (assuming it&#8217;s running in EC2). </li>
</ul>

<h3>Considerations</h3>

<p>It&#8217;s going to be hard to beat the speed of memcached. As far as speed is concerned, I&#8217;m using built-in Python stuff including urllib, httplib, xml.sax, etc (all of which are used by Boto). It might be worthwhile to write a C implementation of the S3 communication methods (but maybe not). The most costly part of this code aside from network communication is probably the serialization, and since cPickle is used there is not really improvement to be made there.</p>

<p>It might be cool to couple the meta-data with SimpleDB.</p>

<p>I registered cloudcached.com in case this gains some momentum. I will post updates and benchmarks there as they arrive.</p>

<p>-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/XbW-f94I3YA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/06/weekend-project-cloudcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/06/weekend-project-cloudcached/</feedburner:origLink></item>
		<item>
		<title>First (real) MPI run on EC2</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/tOXWkmGltCo/</link>
		<comments>http://mumrah.net/2009/06/first-real-mpi-run-on-ec2/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:22:23 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[ec2mpi]]></category>
		<category><![CDATA[mpi]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=157</guid>
		<description><![CDATA[Running my first non-trivial MPI job on EC2. Yay science!]]></description>
			<content:encoded><![CDATA[<p>After a few days of tinkering with <a title="GitHub project page for EC2MPI" href="http://github.com/mumrah/ec2mpi/tree/master" target="_blank">EC2MPI</a>, I spent some time polishing up a stat mech MPI simulation. The code in question is a 2d Ising model simulation using Replica Exchange. Right now it stands at around 400 lines of C++ using STL vectors (which I love). Once I know it works (or at least works well enough) I might post it up here, but for now I&#8217;m just trying to generate pretty hysteresis plots and observe the critical behavior of a 2d Ising model system. Here&#8217;s a picture with points on it.</p>

<p><div class="wp-caption aligncenter" style="width: 655px"><img class="s3-img  " style="border: 0px initial initial;" src="http://mumrah-dot-net.s3.amazonaws.com/EvM.png" border="0" alt="EvM.png" width="645" height="442" /><p class="wp-caption-text">Energy per spin plotted against magnetization</p></div></p>

<p>I leave the interpretation to you. The best part of this is that I can do these MPI runs without burning a hole in my lap (the MacBook gets rather warm). 
-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/tOXWkmGltCo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/06/first-real-mpi-run-on-ec2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/06/first-real-mpi-run-on-ec2/</feedburner:origLink></item>
		<item>
		<title>Time Machine In Your Pocket – Addendum</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/fWMwhcIfNZw/</link>
		<comments>http://mumrah.net/2009/06/time-machine-in-your-pocket-addendum/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 13:29:50 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=145</guid>
		<description><![CDATA[Addendum to two previoius posts.

The other day, I noticed my 8GB USB volume that I use for temporary incremental backups was quite full. Curious, since the folders I back up to that volume do not total but 200MB or so, and rsync was supposed to be doing incremental backups (link-dest ftw).

After a little searching around, [...]]]></description>
			<content:encoded><![CDATA[<p>Addendum to two <a href="http://mumrah.net/2008/12/time-machine-in-your-pocket/" title="Part 1" target="_self">previoius<a> <a href="http://mumrah.net/2009/03/timemachine-in-your-pocket-part-2/" title="Part 2" target="_self">posts</a>.</p>

<p>The other day, I noticed my 8GB USB volume that I use for temporary incremental backups was quite full. Curious, since the folders I back up to that volume do not total but 200MB or so, and rsync was supposed to be doing incremental backups (link-dest ftw).</p>

<p>After a little searching around, I found someone who had a similar problem (and a solution). When you format a volume with OS X it will, by default, ignore file ownership (the linked article explores why this is perhaps). This proves to be a problem for rsync which considers file permissions and ownership as part of the file stat (as it should). Luckily the fix is easy &#8211; &#8220;Get Info&#8221; for the volume in question, then at the bottom unselect &#8220;Ignore ownership on this volume&#8221;</p>

<div style="text-align: center;"><img class="aligncenter" title="rsync ownership fix" src="http://mumrah-dot-net.s3.amazonaws.com/rsync-ownership-fix.png" alt="Uncheck Ignore ownership ..." width="238" height="49" /></div>

<p><br/></p>

<p>You will probably want to delete any backups that have been created (since they won&#8217;t have the correct file ownership). Source: <a href="http://terminalapp.net/backups-rsync-and-link-dest-not-working/">Terminalapp.net</a></p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/fWMwhcIfNZw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/06/time-machine-in-your-pocket-addendum/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/06/time-machine-in-your-pocket-addendum/</feedburner:origLink></item>
		<item>
		<title>MPI running on Amazon EC2</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/hkez3UvgQ84/</link>
		<comments>http://mumrah.net/2009/05/mpi-running-on-amazon-ec2/#comments</comments>
		<pubDate>Sat, 30 May 2009 23:40:24 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[ec2mpi]]></category>
		<category><![CDATA[mpi]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=130</guid>
		<description><![CDATA[



For my Master&#8217;s thesis, I&#8217;m going to be running a lot of MPI code, and naturally I need a place to run it. Let me first say that my university has an excellent high-performance computing center run by one of my committee chairs that is more than capable of serving my needs &#8211; but yet, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://aws.amazon.com"><img class="  alignright" style="margin-top: 0px; margin-left: 15px; " title="AWS logo" src="http://awsmedia.s3.amazonaws.com/Powered-by-Amazon-Web-Services.jpg" alt="Amazon Web Services" width="127" height="52" /></a></p>

<p><a href="http://www.open-mpi.org/"><img class="   alignright" style="clear: right; margin-top: 20px; margin-left: 15px;" title="OpenMPI" src="http://www.open-mpi.org/images/open-mpi-logo.png" alt="" width="129" height="128" /></a></p>

<p>For my Master&#8217;s thesis, I&#8217;m going to be running a lot of MPI code, and naturally I need a place to run it. Let me first say that my university has an excellent <a title="Florida State University High Performance Computing Center" href="http://hpc.fsu.edu" target="_blank">high-performance computing center</a> run by one of my committee chairs that is more than capable of serving my needs &#8211; but yet, I am unfulfilled. With our scheduling system, there is a &#8220;backfill&#8221; that is always available for running small jobs (like the ones I run), but for my thesis, I want to test the massive scalability of an algorithm (<a title="Replica Exchange, also known as Parallel Tempering" href="http://en.wikipedia.org/wiki/Parallel_tempering" target="_blank">Replica Exchange</a>). When I mean massive, I mean <em>massive</em> &#8211; think 1000 compute nodes or more.</p>

<p>Big ideas, people.</p>

<p>In order to satisfy my need for a massively parallel platform, I looked no further than <a title="Amazon Elastic Computing Cloud" href="http://aws.amazon.com/ec2/" target="_blank">Amazon EC2</a>. As should be apparent from many of my <a title="Posts filed under Amazon" href="http://mumrah.net/topics/amazon/" target="_self">previous posts</a>, I have been doing a lot of work with Amazon&#8217;s cloud services &#8211; both school and work.</p>

<p>A few weeks ago, I started an MIT-licensed open source project on GitHub aptly named <a title="EC2MPI repository on GitHub" href="http://github.com/mumrah/ec2mpi/tree/master" target="_blank">EC2MPI</a>. Today I made a major step forward with this project which was the motivation for this post. I finally have everything configured properly and got my first no-hassle MPI cluster up and running.</p>

<p>The script I wrote (<a title="Another link" href="http://github.com/mumrah/ec2mpi/tree/master" target="_blank">EC2MPI</a>), is written in Python and presents an interactive prompt to the user. You select the architecture (i386 or x64), the number of instances, and I also have support for user-defined SSH keypairs (not AWS keypairs) for cluster security. The instances are spawned, and EC2MPI sets up the SSH keys, as well as MPI configuration. It is so freaking sweet.</p>

<p>I wanted to share some issues I&#8217;ve had so far while developing this and how I solved them.</p>

<p><strong>Intra-EC2 communication</strong> &#8211; For this, I needed each instance to be able to talk to one another for point-to-point as well as collective communication. My solution for this was to allow the user to generate SSH keypairs which were stored in a private S3 bucket (owned by the user). My user-data script sent to the instances took care of downloading and installing the keys upon startup.</p>

<p><strong>Shared storage among instances</strong> &#8211; In order to run MPI code, the nodes in the cluster need access to a shared storage volume which will contain binary files compiled by MPI. Since EC2 has no shared storage (for now), I had to find an alternate solution. The solution I settled on was to use <a target="_blank" title="S3FS Google Code project page" href="http://code.google.com/p/s3fs/">s3fs</a>: a fuse-based filesystem which allows you to mount an S3 bucket as a volume. Reading and writing to the shared volume is pretty slow (unless it&#8217;s cached), so for certain kinds of code this might not be ideal. However, I believe it is the best solution for now. I imagine one day Amazon will add a feature to the Elastic Block Storage volumes that allow them to act as shared volumes.</p>

<p><strong>Starting up and tearing down clusters</strong> &#8211; I used Amazon SimpleDB to keep meta-data about the cluster: how many instances are in the cluster, internal/external IP addresses, etc. This is also how I define the master node and worker nodes. This will allow me to add features such as adding and removing instances from a cluster without having to tear the whole thing down. Also I did all startup config with a user-data script so the script does not have to log into each instance upon startup. This allows the clusters startup to scale well.</p>

<p>Check back soon for some benchmarks and more detailed write-ups as the project progresses. First, I need to get my maximum number of instances increased (right now I can do 20 max). Fast times ahead, friends.</p>

<p>-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/hkez3UvgQ84" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/05/mpi-running-on-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/05/mpi-running-on-amazon-ec2/</feedburner:origLink></item>
		<item>
		<title>Managing multiple AWS accounts</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/DMBu3P4l0H4/</link>
		<comments>http://mumrah.net/2009/05/managing-multiple-aws-accounts/#comments</comments>
		<pubDate>Tue, 12 May 2009 02:41:53 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=113</guid>
		<description><![CDATA[ On my personal computer, I have three sets of x509 certificates/private keys. This makes using the EC2-API-tools quite the hassle. Echoes of EC2_CERT and EC2_PRIVATE_KEY haunt my dreams.

So, like you do with these sort of things, I wrote a bash script to work some magic.



    #!/bin/bash
    echo "Choose [...]]]></description>
			<content:encoded><![CDATA[<p><a style="clear:both;" href="http://mumrah-dot-net.s3.amazonaws.com/ec2-account.jpg"><img class="s3-img alignright" style="border: 0pt none;" src="http://mumrah-dot-net.s3.amazonaws.com/ec2-account.jpg" border="0" alt="ec2-account.jpg" width="283" height="188" /></a> On my personal computer, I have three sets of x509 certificates/private keys. This makes using the EC2-API-tools quite the hassle. Echoes of EC2_CERT and EC2_PRIVATE_KEY haunt my dreams.
<br/><br/>
So, like you do with these sort of things, I wrote a bash script to work some magic.
<br/></p>

<p><pre name="code">
    #!/bin/bash
    echo "Choose Account:"
    read account
    base=<code>grep $account ~/.ec2/README -i | awk '{print $1}'</code>
    if [ ! -n "$base" ]; then
        echo "Sorry, that account does not exist"
        return
    fi
    declare -x EC2_CERT="~/.ec2/cert-$base.pem"
    declare -x EC2_PRIVATE_KEY="~/.ec2/pk-$base.pem"
    echo "EC2 environment updated"
</pre></p>

<p>Requires that you your private keys/certs in ~/.ec2, and they are named cert-{something}.pem and pk-{something}.pem. Also, you need a README file in ~/.ec2 that looks like
<pre name="code">
    something account1
    something-else account2
</pre><br/>
I setup an alias so I just run &#8220;ec2-account personal&#8221; to switch to my personal credentials, and &#8220;ec2-account work&#8221; to switch to my work account.</p>

<p>-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/DMBu3P4l0H4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/05/managing-multiple-aws-accounts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/05/managing-multiple-aws-accounts/</feedburner:origLink></item>
		<item>
		<title>Funded!</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/_rguQXyUtWc/</link>
		<comments>http://mumrah.net/2009/05/funded/#comments</comments>
		<pubDate>Tue, 05 May 2009 20:00:50 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[aws]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=94</guid>
		<description><![CDATA[Amazon gave me money!]]></description>
			<content:encoded><![CDATA[<p><img class="s3-img alignright" style="border: 0pt none; margin: 5px;" src="http://mumrah-dot-net.s3.amazonaws.com/fake-money.jpg" border="0" alt="monopoly-money1.jpg" width="200" height="200" />Amazon issued me 300 dollars in EC2 credits to support Master&#8217;s project. Very exciting.</p>

<p>If you&#8217;re a university researcher, student, or professor, visit <a title="AWS in Education" href="http://aws.amazon.com/education/" target="_blank">http://aws.amazon.com/education</a> for more information. One of my professors talked to me about giving a seminar on cloud computing in the fall. I believe these types of grants are issued for that sort of thing as well.</p>

<p>Totally putting this on my CV.</p>

<div style="clear:both"></div>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/_rguQXyUtWc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/05/funded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/05/funded/</feedburner:origLink></item>
		<item>
		<title>Serve gzipped content from Amazon S3</title>
		<link>http://feedproxy.google.com/~r/NullDisquisition/~3/G6An3ywYR0E/</link>
		<comments>http://mumrah.net/2009/05/serve-gzipped-content-from-amazon-s3/#comments</comments>
		<pubDate>Tue, 05 May 2009 04:15:04 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://mumrah.net/?p=70</guid>
		<description><![CDATA[Set Content-encoding to gzip. Bam, done.]]></description>
			<content:encoded><![CDATA[<div class="mceTemp"><dl class="wp-caption alignright" style="width: 210px;"> <dt class="wp-caption-dt"><a href="http://mumrah-dot-net.s3.amazonaws.com/zipper.jpg"><img class="s3-img" style="border: 0pt none;" src="http://mumrah-dot-net.s3.amazonaws.com/zipper_thumb.gz.jpg" border="0" alt="gzipper" width="200" height="164" /></a></dt> </dl></div>

<p>Set the &#8220;Content-encoding&#8221; header to &#8220;gzip&#8221;. Really, it&#8217;s that easy.</p>

<p>Kthxbye.</p>

<p>Well, since you came all this way, I&#8217;ll give a little more detail. First, make a file.</p>

<p>Now gzip it.</p>

<p>Upload it.</p>

<p>Find a utility that can modify file headers on S3: <a title="S3Hub homepage" href="http://s3hub.com/" target="_blank">S3Hub</a> (OS X), <a title="Cloudberry S3 Explorer product page" href="http://cloudberrylab.com/default.aspx?page=cloudberry-explorer-amazon-s3" target="_blank">Cloudberry S3 Explorer</a> (Windows), or any of the <a title="Boto for Python" href="http://code.google.com/p/boto/" target="_blank">various</a> <a title="PHP S3 library" href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=126" target="_blank">3rd</a> <a title="Ruby Library for AWS" href="http://amazon.rubyforge.org/" target="_blank">party</a> <a title="Perl module for AWS" href="http://search.cpan.org/~lbrocard/Net-Amazon-S3-0.50/lib/Net/Amazon/S3.pm" target="_blank">libraries</a>.</p>

<p>Set the Content-type header to whatever the appropriate content type is: text/plain, text/css, text/javascript, image/jpeg, etc.</p>

<p>Set the Content-encoding to gzip.</p>

<p>Pat yourself on the back.</p>

<p>Here&#8217;s three versions of a text file I made and gzipped. Note that with appropriate headers, file extensions don&#8217;t mean squat.</p>

<ol>
    <li><a href="http://mumrah-dot-net.s3.amazonaws.com/gziptest.txt.gz" target="_self">http://mumrah-dot-net.s3.amazonaws.com/gziptest.txt.gz</a></li>
    <li><a href="http://mumrah-dot-net.s3.amazonaws.com/gziptest.txt" target="_self">http://mumrah-dot-net.s3.amazonaws.com/gziptest.txt</a></li>
    <li><a href="http://mumrah-dot-net.s3.amazonaws.com/gziptest" target="_self">http://mumrah-dot-net.s3.amazonaws.com/gziptest</a></li>
</ol>

<p>Go ahead and download one &#8211; you&#8217;ll see that the file is actually gzipped and your browser is doing the deflating on the fly. This is the same effect producted by mod_deflate in Apache.</p>

<p>-David</p>
<img src="http://feeds.feedburner.com/~r/NullDisquisition/~4/G6An3ywYR0E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mumrah.net/2009/05/serve-gzipped-content-from-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://mumrah.net/2009/05/serve-gzipped-content-from-amazon-s3/</feedburner:origLink></item>
	</channel>
</rss><!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
