<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Benji on Launchpad Blog</title>
    <link>https://blog.launchpad.net/authors/benji/</link>
    <description>News and updates from the Launchpad team</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 27 Mar 2012 12:15:58 +0000</lastBuildDate>
    <atom:link href="https://blog.launchpad.net/feed/authors/benji/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Parallelising the Unparallelisable</title>
      <link>https://blog.launchpad.net/general/parallelising-the-unparallelisable/</link>
      <pubDate>Tue, 27 Mar 2012 12:15:58 +0000</pubDate>
      <dc:creator>Benji York</dc:creator>
      <guid isPermaLink="false">https://blog.launchpad.net/?p=3253</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://blog.launchpad.net/images/posts/2012/03/37179226_2d1183c198.jpg&#34;&gt;&lt;img src=&#34;https://blog.launchpad.net/images/posts/2012/03/37179226_2d1183c198-300x203.jpg&#34; alt=&#34;&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Launchpad has a lot of tests, almost 20,000. There are tests that make sure the internals work as expected, that verify the Javascript works in web browsers, and everything in between. In a perfect world those tests would only take seconds to run. In this world they take hours; six hours on our current continuous integration machines, for instance.&lt;/p&gt;
&lt;p&gt;These long-running tests severely impact the time it takes to develop and deploy changes to Launchpad. We would like to improve the situation.&lt;/p&gt;
&lt;p&gt;Given that the test cases are theoretically independent of one another, the obvious thing to do is to run the tests in parallel on a multi-core machine. Unfortunately many of the tests interact with the environment (databases, memcached, temporary directories, etc.) and conflict if run simultaneously.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Enter LXC&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What we need is a way to isolate the test processes from each another. Virtual machines would allow us to do that, but the overhead and heavy-weight setup makes them unappealing. That&amp;rsquo;s where &lt;a href=&#34;http://lxc.sourceforge.net/&#34;&gt;LXC&lt;/a&gt; (Linux Containers) comes in handy. LXC&lt;/p&gt;
&lt;p&gt;allows the easy creation of &amp;ldquo;containers&amp;rdquo; that are isolated from the &amp;ldquo;host&amp;rdquo; machine without the performance overhead of VMs.&lt;/p&gt;
&lt;p&gt;For example, to create a new container use lxc-create:&lt;/p&gt;
&lt;p&gt;lxc-create -n test -t ubuntu&lt;/p&gt;
&lt;p&gt;The container can then be started:&lt;/p&gt;
&lt;p&gt;lxc-start -n test -d&lt;/p&gt;
&lt;p&gt;And we can connect to it via SSH (using the default username and password shown during creation, if applicable):&lt;/p&gt;
&lt;p&gt;ssh ubuntu@test&lt;/p&gt;
&lt;p&gt;There are many options for customising the containers, including mounting a portion of the host&amp;rsquo;s file system in the container so sharing files between the two is easy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Getting Ephemeral&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;All this is very nice for running isolated, parallel test runs but setting up and managing eight or more containers (one per core) is&lt;br&gt;
off-putting, so we have used (and improved) a new LXC feature, &amp;ldquo;ephemeral&amp;rdquo; containers (created with lxc-start-ephemeral).&lt;/p&gt;
&lt;p&gt;Ephemeral containers are &amp;ldquo;clones&amp;rdquo; of a base container and can have a temporary file system that reflects the contents of the base container but any writes are stored in-memory and are not written to disk. This allows us to install Launchpad on a single base container and then spawn many ephemeral containers, each with their own list of tests to run.&lt;/p&gt;
&lt;p&gt;The ephemeral containers can then write to their local file systems without interfering with the others running simultaneously. The&lt;br&gt;
containers may also benefit from faster IO because of the file system changes being stored in memory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Results&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We are still working out the kinks in our approach and wrestling with the occasional LXC bug as well as bugs in the Launchpad test suite itself. Even so we have already shortened a full test run on an eight-core EC2 instance down to 45 minutes; a substantial improvement over the current six hours.&lt;/p&gt;
&lt;p&gt;(Image by &lt;a href=&#34;http://www.flickr.com/photos/eob/&#34;&gt;Tolka Rova&lt;/a&gt;, Creative Commons license)&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
