<?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>geek thoughts &#187; solutions</title>
	<atom:link href="http://www.mlesniak.com/category/solutions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mlesniak.com</link>
	<description></description>
	<lastBuildDate>Wed, 12 May 2010 09:04:09 +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>Ubuntu 64 Bit and GHCs Garbage Collector</title>
		<link>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/</link>
		<comments>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 07:38:19 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[solutions]]></category>

		<guid isPermaLink="false">http://www.mlesniak.com/?p=646</guid>
		<description><![CDATA[Hi, Update: I tested a kernel 2.6.31-12 (from kernel.org) and had the same (if not even worse) behaviour as with 2.6.31-19. So, I apologize. It has nothing to do with Ubuntu per se, but probably with the linux-kernel; that makes me wonder if I haven&#8217;t done something faulty: that behaviour should have attracted the attention [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p><em><strong>Update</strong>: I tested a kernel 2.6.31-12 (from kernel.org) and had the same (if not even worse) behaviour as with 2.6.31-19. So, I apologize. It has nothing to do with Ubuntu per se, but probably with the linux-kernel; that makes me wonder if I haven&#8217;t done something faulty: that behaviour should have attracted the attention of some other Haskell developers in the meantime, but I couldn&#8217;t find any information on it. So, take in mind that the following could be incorrect&#8230;</em></p>
<p>finding this strange behaviour had cost me a lot of hours (see also my <a href="http://www.haskell.org/pipermail/haskell-cafe/2010-March/073938.html">post</a> on the haskell-cafe mailing list), because honestly, who do you blame if your parallel programm behaves strangely:</p>
<ol>
<li>yourself</li>
<li>the compiler</li>
<li>the special patches of your OS vendor to your linux kernel</li>
</ol>
<p>Since the probabilities of an error in 2. are quite low (at lot of people use GHC and its parallelization techniques) and &#8212; at least I thought that &#8212; those in 3. are low, too (some of those people from 1. should be using my OS with GHC for parallel development), I chose 1. Hence, I spent a lot of time trying to find synchronisation and performance problems in my code, which in fact, weren&#8217;t there!</p>
<p>The current setup of a standard Ubuntu 9.10 (64 bit) is a vanilla kernel (2.6.31-19-generic) , used with GHC 6.12.1. Look at this small and seemingly innocent program</p>
<pre lang="haskell'">-- File Pi.hs
-- you need the numbers package from hackage.
module Main where
import Data.Number.CReal
import System.Environment
import GHC.Conc

main = do
    digits &lt;- (read . head) `fmap` getArgs :: IO Int
    showCReal (fromEnum digits) pi `pseq` return ()
</pre>
<p>that you can compile with</p>
<pre>ghc -- make -O2 -threaded Pi.hs -o pi
</pre>
<p>Benchmarking with</p>
<pre>for i in `seq 1 5`;do time pi 5000 +RTS -N1;done
for i in `seq 1 5`;do time pi 5000 +RTS -N2;done</pre>
<p>I received the following exemplary runtimes for the vanilla ubuntu kernel.</p>
<p><br class="spacer_" /></p>
<p><a href="http://www.mlesniak.com/wp-content/uploads/2010/03/bad.png"><img class="aligncenter size-full wp-image-648" title="bad" src="http://www.mlesniak.com/wp-content/uploads/2010/03/bad.png" alt="" width="354" height="310" /></a></p>
<p>And this is the threadscope profile of a particular bad run:</p>
<p><img class="aligncenter size-full wp-image-650" title="thread" src="http://www.mlesniak.com/wp-content/uploads/2010/03/thread.png" alt="" width="583" height="247" /><br />
 As you can see, nearly all time is spend in the Garbage Collector, doing&#8230;things, GCs do&#8230;</p>
<p>I then compiled my own kernel2.633 from kernel.org and received these results:</p>
<p><a href="http://www.mlesniak.com/wp-content/uploads/2010/03/good.png"><img class="aligncenter size-full wp-image-649" title="good" src="http://www.mlesniak.com/wp-content/uploads/2010/03/good.png" alt="" width="354" height="310" /></a></p>
<p><strong>Conclusion:</strong> At least for me and my parallel programs (and even some innocent toy programs like Pi.hs) does the standard Ubuntu 64bit kernel harm parallel performance (especially that of the GC) a lot.</p>
<p>I find this highly surprising:</p>
<ul>
<li>Ubuntu is a widely used distribution</li>
<li> 64 bit versions are also becoming quite common</li>
<li>in my perception Haskell developers use parallelism a lot</li>
</ul>
<p><strong>Question. </strong>Either the intersection of these properties is quite small or my measurements have some serious flaw. I&#8217;d be glad if someone could disprove my results (and give me the opportunity to learn a bit) or support my measurements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
