<?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>codeaholics.org</title>
	
	<link>http://blog.codeaholics.org</link>
	<description>addicted to codeahol since 1985</description>
	<lastBuildDate>Tue, 02 Oct 2012 20:39:36 +0000</lastBuildDate>
	<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/codeaholics-uk" /><feedburner:info uri="codeaholics-uk" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Emulating Maven’s “provided” scope in Gradle</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/-TTufAZk07U/</link>
		<comments>http://blog.codeaholics.org/2012/emulating-mavens-provided-scope-in-gradle/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 20:27:28 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Build]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=252</guid>
		<description><![CDATA[I&#8217;m not a fan of Maven. I don&#8217;t make any secret of it. But one thing they&#8217;ve got right is the &#8220;provided&#8221; scope &#8211; that is, a scope whose dependencies are used at compile time, but not required at runtime because they&#8217;re expected to already be present. The canonical example of the use of this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a fan of Maven. I don&#8217;t make any secret of it. But one thing they&#8217;ve got right is the &#8220;provided&#8221; scope &#8211; that is, a scope whose dependencies are used at compile time, but not required at runtime because they&#8217;re expected to already be present. The canonical example of the use of this scope is the Servlet or JSP API &#8211; it needs to be present at compile time to compile against, but the container provides it at runtime, so it doesn&#8217;t need to be explicitly pulled in as a runtime dependency.</p>
<p>I <em>am</em> however, a big fan of Gradle. Gradle&#8217;s Java plugin provides a number of default &#8220;configurations&#8221; (revealing Gradle&#8217;s close relationship to Ivy) which bear a close resemblance to Maven&#8217;s scopes. However, the Java plugin doesn&#8217;t provide anything like Maven&#8217;s &#8220;provided&#8221; scope. (Note: the War plugin <em>does</em> provide both &#8220;providedCompile&#8221; and &#8220;providedRuntime&#8221; configurations.)</p>
<p>Why would you want a &#8220;provided&#8221; configuration in a Java project? Well, my particular use case was that I was writing a custom Ant task (I&#8217;m aware of the irony of using Gradle to build this!) and I needed to compile against the Ant API &#8211; but, of course, at run time the Ant JAR is already present.</p>
<p>Having pieced together a number of posts on the internet, I came up with the following:</p>
<pre class="brush: groovy; title: ; notranslate">
configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

dependencies {
    provided 'org.apache.ant:ant:1.8.4'
}
</pre>
<p>This works, but it feels a bit dirty.</p>
<p>If you&#8217;re an Eclipse user (of course you are!) it also has one major flaw. If you&#8217;re using the Eclipse STS Gradle plugin to create a managed classpath in your Eclipse project (rather than using Gradle&#8217;s Eclipse plugin to generate your <code>.classpath</code> and <code>.project</code> files), you&#8217;ll find that Eclipse doesn&#8217;t know anything about your &#8220;provided&#8221; dependencies and you have a bunch of compile errors.</p>
<p>Here&#8217;s how to sort that out:</p>
<pre class="brush: groovy; title: ; notranslate">
apply plugin: 'eclipse'

eclipse.classpath.plusConfigurations += configurations.provided
</pre>
<p>So, you have to add Gradle&#8217;s Eclipse plugin &#8211; even if you wouldn&#8217;t otherwise be using it &#8211; and add your &#8220;provided&#8221; dependencies to the Eclipse classpath configuration. Even if you don&#8217;t use the Gradle Eclipse plugin, the Eclipse STS Gradle plugin uses the same model and will now pick up your &#8220;provided&#8221; dependencies.</p>
<p>There is an outstanding Gradle bug report/enhancement request for this feature, but for some reason it&#8217;s struggling to get traction. If you feel this is important enough to be a built-in part of the Gradle Java plugin, please vote for <a href="http://issues.gradle.org/browse/GRADLE-784" target="_blank">this issue</a>.</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/-TTufAZk07U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2012/emulating-mavens-provided-scope-in-gradle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2012/emulating-mavens-provided-scope-in-gradle/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=emulating-mavens-provided-scope-in-gradle</feedburner:origLink></item>
		<item>
		<title>World’s fastest break-in attempt</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/ebDnQLdtdos/</link>
		<comments>http://blog.codeaholics.org/2012/worlds-fastest-break-in-attempt/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 19:14:16 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=244</guid>
		<description><![CDATA[Actually, I&#8217;m pretty sure it isn&#8217;t, but still&#8230; From spinning up a new EC2 instance today to getting the first e-mail from fail2ban took a little under 6 hours. I don&#8217;t know if this makes me happy or sad. Happy because I have a Puppet-based bootstrap system which can bring a freshly minted box up [...]]]></description>
			<content:encoded><![CDATA[<p>Actually, I&#8217;m pretty sure it isn&#8217;t, but still&#8230;</p>
<p>From spinning up a new EC2 instance today to getting the first e-mail from <a href="http://www.fail2ban.org" title="fail2ban" target="_blank">fail2ban</a> took a little under 6 hours.</p>
<p>I don&#8217;t know if this makes me happy or sad. Happy because I have a <a href="http://puppetlabs.com/" title="Puppet Labs" target="_blank">Puppet-based</a> bootstrap system which can bring a freshly minted box up to code in around 5 minutes (including <code>iptables</code>, <code>fail2ban</code> and a locked down SSH configuration), or sad because&#8230; well&#8230; have people really got nothing better to do?</p>
<p>In related news, when <em>will</em> <code>fail2ban</code> support IPv6? There seem to be lots of threads in lots of different issue tracking systems (most lately <a href="https://github.com/fail2ban/fail2ban/issues" title="Github" target="_blank">Github</a>), many of which include patches, but no actual IPv6 action. Now <em>that</em> makes me sad. <img src="http://blog.codeaholics.org/wp-includes/images/smilies/icon_sad.gif?d7148e" alt=':-(' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/ebDnQLdtdos" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2012/worlds-fastest-break-in-attempt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2012/worlds-fastest-break-in-attempt/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=worlds-fastest-break-in-attempt</feedburner:origLink></item>
		<item>
		<title>WordPress, nginx, W3TC and robots.txt</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/9eEOTFd-_-0/</link>
		<comments>http://blog.codeaholics.org/2012/wordpress-nginx-w3tc-and-robots-txt/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 15:29:58 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=234</guid>
		<description><![CDATA[A quick note to try and save somebody else the hours of pain I just experienced&#8230; Here&#8217;s the scenario: you&#8217;re being dead clever and ditching Apache in favour of Nginx to run your WordPress blog/site and pretty much have everything right. You&#8217;re NOT using a plugin to generate robots.txt for you &#8211; after all, WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>A quick note to try and save somebody else the hours of pain I just experienced&#8230;</p>
<p>Here&#8217;s the scenario: you&#8217;re being dead clever and ditching Apache in favour of Nginx to run your WordPress blog/site and pretty much have everything right. You&#8217;re NOT using a plugin to generate <code>robots.txt</code> for you &#8211; after all, WordPress does a good enough job through the <code>Settings > Privacy page</code>. You browse to <code>http://domain.com/robots.txt</code> and everything looks pretty sweet. Heck, you might even go and change the privacy settings and grab <code>robots.txt</code> again to make sure it&#8217;s all working the way you expect.</p>
<p>Then&#8230; you drop the <a href="http://wordpress.org/extend/plugins/w3-total-cache/" title="W3 Total Cache" target="_blank">W3 Total Cache</a> bomb. Now, W3TC is pretty well regarded, but it hasn&#8217;t had any love for a several months. In fact, it hasn&#8217;t even been updated to say it&#8217;s compatible with WordPress 3.3.0+ (which it appears to be, AFAICT, although some people have had issues with Minify). What it <em>does</em> have though, is Nginx support out of the box.</p>
<p>What does that mean? Well, if W3TC detects that it is running on Nginx, it will write out a snippet of Nginx configuration which deals with all the cleverness needed to get Nginx to serve W3TC page cache files statically off the disk without having to go through PHP. (This, my friends, is a large part of the secret sauce that makes an Nginx/PHP stack so much faster than Apache/PHP.) Theoretically, all you have to do is use the <code>include</code> directive to pull this snippet into your virtual host configuration file, and you&#8217;re good to go. (If you do this then don&#8217;t forget to <code>nginx -s reload</code> every time you tweak your W3TC settings.)</p>
<p>And then it hits you. <code>robots.txt</code> has stopped working.</p>
<p>Here&#8217;s my solution (in my virtual host file, if you care):</p>
<pre class="brush: plain; title: ; notranslate">
    location = /robots.txt {
        # Force robots.txt through the PHP. This supercedes a match in the
        # generated W3TC rules which forced a static file lookup
        rewrite ^ /index.php;
    }
</pre>
<p>This is a pretty specific location (using <code>=</code> and not having a regexp), so it trumps anything in the W3TC generated config. Any request for <code>robots.txt</code> is rewritten to <code>index.php</code> which your regular Nginx rules should then hand off to PHP-FPM, which means WordPress will dynamically generate the content for you.</p>
<p>Wow. That took me, literally, 2-3 hours to figure out. Mostly because I didn&#8217;t notice it had stopped working when I added W3TC into the mix. Once I&#8217;d figured out W3TC (or rather the W3TC generated config) was the culprit, the actual fix was pretty quick.</p>
<p>I&#8217;ll be writing more about my Nginx config and the relative performance against Apache2 on an Amazon EC2 Micro instance soon. In the mean time, I hope I saved you some time!</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/9eEOTFd-_-0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2012/wordpress-nginx-w3tc-and-robots-txt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2012/wordpress-nginx-w3tc-and-robots-txt/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wordpress-nginx-w3tc-and-robots-txt</feedburner:origLink></item>
		<item>
		<title>Adventures with DD-WRT and IPv6 (with a dash of TomatoUSB)</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/Y2XDilNPm0I/</link>
		<comments>http://blog.codeaholics.org/2012/adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 21:59:59 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=199</guid>
		<description><![CDATA[A little under a year ago, I decided two things: first, that it was about time my ageing home network got GigE and 5GHz wireless-N (dual band, of course, to support devices that would only do 2.4GHz); and second, that I would separate the jobs of BEING my network from CONNECTING my network to the [...]]]></description>
			<content:encoded><![CDATA[<p>A little under a year ago, I decided two things: first, that it was about time my ageing home network got GigE and 5GHz wireless-N (dual band, of course, to support devices that would only do 2.4GHz); and second, that I would separate the jobs of BEING my network from CONNECTING my network to the internet (since I couldn&#8217;t find a good router which would meet these requirements AND had an ADSL modem in it).</p>
<p>So I bought a Linksys/Cisco E3000, made it the backbone of my network and connected it to the internet via my ISP-supplied ADSL modem.</p>
<p>Then an unfortunate incident happened which involved the Linksys/Cisco setup CD, an unwanted but non-removable guest WiFi network, and me swearing a lot.</p>
<p>The time had come (after about 16 hours!) to put <a href="http://www.dd-wrt.com/">DD-WRT</a> on my router. As <a href="http://www.dslreports.com/forum/remark,26665609" target="_blank">this post</a> describes, choosing a version of DD-WRT that won&#8217;t &#8220;brick&#8221; your router (as the developers like to describe it) is treacherous to say the least. I eventually settled on <code>dd-wrt.v24-16758_NEWD-2_K2.6_mega</code> (specifically, the <code>nv60k</code> version). Despite the trepidation caused by the dire warnings on the web site, the flashing went well, and I&#8217;ve been pleased with DD-WRT ever since. Until&#8230;</p>
<p>Last week, I had a 40Mbit/sec fibre broadband connection installed. Amongst other things, <a href="http://aaisp.net.uk/">my new ISP</a> provides me with a block of IPv6 addresses. Actually 2^80 of them. I seriously need to think about what I&#8217;m going to do with them all.</p>
<p>My excitement at having 1,208,925,819,614,629,174,706,176 IP addresses was somewhat dampened when, after a day or so of fiddling and researching, I discovered that DD-WRT&#8217;s supposed IPv6 support was limited to the various types of v6-over-v4 tunnels (e.g. <a href="http://tunnelbroker.net/">Hurricane Electric</a>). Specifically, the PPP daemon doesn&#8217;t support IPv6 &#8211; so this might just be an issue for PPPoE users. There was no way for me to use all that space natively.</p>
<p>It should be noted here that even if you do want to use a tunnel to reach the IPv6 internet, you will still need to write startup scripts for DD-WRT to load the kernel module (the &#8220;Enable IPv6&#8243; checkbox doesn&#8217;t actually do anything), start <code>radvd</code> (the &#8220;Enable radvd&#8221; checkbox doesn&#8217;t actually do anything), configure the tunnel interfaces and WAN IP addresses, etc. And even after all of this, you&#8217;ll find that the IPv6 user tools (ip6tables, ping6, traceroute6, etc.) aren&#8217;t installed, so you&#8217;ll have to locate them and hope you have room on your device somewhere.</p>
<p>So the time has come to make the move to <a href="http://tomatousb.org/">TomatoUSB</a>. To some extent, this suffers from the same issues as DD-WRT when it comes to variants, etc., but the information is more logically presented, and there do seem to be fewer choices and fewer potential traps. After looking at the comparison of &#8220;mods&#8221; on <a href="http://en.wikipedia.org/wiki/Tomato_(firmware)">Wikipedia</a>, I chose Toastman&#8217;s mod. It seems to have all the features I wanted and he seems to do frequent builds with all the latest updates and patches &#8211; in fact, the latest build (1.28.7494.3) was made only 6 days ago. This compares well with DD-WRT which doesn&#8217;t appear to have had any real active work/releases for a year or so now.</p>
<p>My first impressions of TomatoUSB are positive. The GUI feels snappy, and has most of the same features as DD-WRT. The real-time bandwidth monitor is definitely prettier than DD-WRTs. And, most importantly, the IPv6 support works out of the box.</p>
<p><a href="http://blog.codeaholics.org/2012/adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb/tomato-ipv6-3/" rel="attachment wp-att-215"><img src="http://blog.codeaholics.org/wp-content/uploads/2012/01/tomato-ipv62.png?d7148e" alt="TomatoUSB IPv6 configuration screen" title="tomato-ipv6" width="901" height="870" class="aligncenter size-full wp-image-215" /></a></p>
<p>Out-of-the-box, <code>ip6tables</code> is configured to allow ICMP packets of every type (so I can ping all my machines from various online ping sites), but disallow all inbound traffic. So, Linux ip6tables bugs aside, I&#8217;m secure by default, which is nice. There doesn&#8217;t seem to be a GUI interface to setup firewall rules for IPv6, so I guess if I ever to want to let anything in, I&#8217;ll have to ssh to the router and do it by hand &#8211; but why would I ever want that?</p>
<p>And that&#8217;s that. I took under 2 hours to flash TomatoUSB, reproduce all my configuration on it, and get IPv6 working. Nice. I can now browse <a href="http://ipv6.google.com/">ipv6.google.com</a>, <a href="http://www.v6.facebook.com">www.v6.facebook.com/</a>, and I get a dancing turtle when I visit <a href="http://www.kame.net/">www.kame.net</a>. Also, this:</p>
<p><a href="http://blog.codeaholics.org/2012/adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb/test-ipv6-screenshot/" rel="attachment wp-att-212"><img src="http://blog.codeaholics.org/wp-content/uploads/2012/01/test-ipv6-screenshot-1024x980.png?d7148e" alt="Results from test-ipv6.com" title="test-ipv6-screenshot" width="1024" height="980" class="aligncenter size-large wp-image-212" /></a></p>
<p><b>One last thing:</b> don&#8217;t forget to enable IPv6 privacy extensions on all of your hosts!</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/Y2XDilNPm0I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2012/adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2012/adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=adventures-with-dd-wrt-and-ipv6-with-a-dash-of-tomatousb</feedburner:origLink></item>
		<item>
		<title>iTunes 10.5 upgrade woes</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/cW8BFrJ58RY/</link>
		<comments>http://blog.codeaholics.org/2011/itunes-10-5-upgrade-woes/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 21:26:02 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=195</guid>
		<description><![CDATA[iOS 5 is upon us, so I thought I would snag a copy and see what&#8217;s what. But, first thing&#8217;s first&#8230; I apparently needed to upgrade iTunes to 10.5. (Why? Why do I need a particular version of a media player to install a particular version of a mobile phone OS?) I&#8217;m running Windows Vista [...]]]></description>
			<content:encoded><![CDATA[<p>iOS 5 is upon us, so I thought I would snag a copy and see what&#8217;s what. But, first thing&#8217;s first&#8230; I apparently needed to upgrade iTunes to 10.5. (Why? Why do I need a particular version of a media player to install a particular version of a mobile phone OS?)</p>
<p>I&#8217;m running Windows Vista (yes, really) Ultimate x64 SP2 with all current patches applied. After the obligatory unchecking of unwanted crap from the Apple software update tool (specifically, MobileMe and Safari), I settled in to watch the very slow download. I guess Apple&#8217;s servers are a bit overloaded right now. And then the very slow installation process begins. And then&#8230; the very slow installation process aborts.</p>
<p>Hmmm. Try again. At least it didn&#8217;t seem to need to do the download again. Same failure. No real error message. Just &#8220;failed to install&#8221; or something equally unhelpful.</p>
<p>A quick Google turned up lots of people having this problem. Some on Windows 7, some on Vista. All on x64. The typical advice was to try installing as an administrator, try downloading and running the MSI by hand, try both (manual install as an administrator). None of it helped. It did, however, reveal a more useful error message. “Service ‘iPod Service’ (iPod Service) could not be installed. Verify that you have sufficient privileges to install system services.”</p>
<p>Googling this turned up <a href="http://planetmediocrity.com/2010/09/itunes-10-installation-problem-and-solution/">a year-old blog post by David Lesault</a> which hit the spot.</p>
<p>Essentially, it seems the installer has issues uninstalling the iPod Service sometimes (I&#8217;ve never had this problem before, others seem to have had it since the genesis of iTunes 10.x). The service is marked for deletion, but not quite gone yet. Hence trying to install the new version of the service failed. This is similar to that funky Windows things where it can&#8217;t delete files that are in use by a process, but remembers them and deletes them when you reboot. Which, incidentally, is one of the primary reasons why Windows insists on reboots after various kinds of patches, although this is much, much better in Vista and later.</p>
<p>So, I slightly altered David&#8217;s process. I got myself to the error message and then simply switched my machine off (hold the power button for 4 seconds). When I restarted and tried the install again, MSI said that a pending installation was in progress and I would need to roll that back before continuing, which I duly did. I was a bit worried that the &#8220;rollback&#8221; would reinstall the old version of the service, but it didn&#8217;t seem to. And that&#8217;s that&#8230; the iTunes 10.5 upgrade successfully installed.</p>
<p>Now, only 7 minutes left of the iOS 5 download, and who knows how long it will take to actually upgrade the phone and what issues I will have&#8230;?</p>
<p>Thanks Apple. :-/</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/cW8BFrJ58RY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/itunes-10-5-upgrade-woes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/itunes-10-5-upgrade-woes/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=itunes-10-5-upgrade-woes</feedburner:origLink></item>
		<item>
		<title>Disruptor.NET</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/N0612qLp3CA/</link>
		<comments>http://blog.codeaholics.org/2011/disruptor-net/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 19:53:13 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=177</guid>
		<description><![CDATA[It&#8217;s interesting to see people getting interested in porting the Disruptor to .NET (although what&#8217;s wrong with The One True Language, I don&#8217;t know!). Tim Gebhardt has a port on Github Matt Davey (Technical Director at Lab49) also has a couple of posts about porting the Disruptor and comparing the performance of his port to [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s interesting to see people getting interested in porting the Disruptor to .NET (although what&#8217;s wrong with The One True Language, I don&#8217;t know!).</p>
<ul>
<li>Tim Gebhardt has <a href="https://github.com/TimGebhardt/Disruptor.NET">a port</a> on Github</li>
<li>Matt Davey (Technical Director at Lab49) also has a couple of posts about <a href="http://mdavey.wordpress.com/2011/06/30/disruptor-net-concurrent-programming-framework-for-net-framework/">porting the Disruptor</a> and <a href="http://mdavey.wordpress.com/2011/06/30/initlal-java-vs-net-disruptor-performance-comparison/">comparing the performance</a> of his port to the Java version</li>
</ul>
<p>I&#8217;ll try to keep this post updated as I learn of more .NET interest. Alternatively, please feel free to post a comment below.</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/N0612qLp3CA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/disruptor-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/disruptor-net/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=disruptor-net</feedburner:origLink></item>
		<item>
		<title>The Disruptor – Lock-free publishing</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/quVAdd1quoA/</link>
		<comments>http://blog.codeaholics.org/2011/the-disruptor-lock-free-publishing/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 16:57:11 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=156</guid>
		<description><![CDATA[In case you&#8217;ve been living on another planet, we recently our high performance message passing framework. I&#8217;m going to give a quick run-down on how we put messages into the ring buffer (the core data structure within the Disruptor) without using any locks. Before going any further, it&#8217;s worth a quick read of Trish&#8217;s post, [...]]]></description>
			<content:encoded><![CDATA[<p>In case you&#8217;ve been living on another planet, we recently <a href="http://blog.codeaholics.org/2011/open-sourcing-the-disruptor/">open-sourced</a> <a href="http://mikes-tech.blogspot.com/2011/06/disruptor-now-open-source.html" target="_blank">our</a> <a href="http://mechanitis.blogspot.com/2011/06/dissecting-disruptor-whats-so-special.html" target="_blank">high</a> <a href="http://www.davefarley.net/?p=151" target="_blank">performance</a> <a href="http://code.google.com/p/disruptor/" target="_blank">message passing framework</a>.</p>
<p>I&#8217;m going to give a quick run-down on how we put messages into the ring buffer (the core data structure within the Disruptor) without using any locks.<br />
<span id="more-156"></span><br />
Before going any further, it&#8217;s worth a quick read of <a href="http://mechanitis.blogspot.com/2011/06/dissecting-disruptor-whats-so-special.html" target="_blank">Trish&#8217;s post</a>, which gives a high-level overview of the ring buffer and how it works.</p>
<p>The salient points from this post are:</p>
<ol>
<li>The ring buffer is nothing but a big array.</li>
<li>All &#8220;pointers&#8221; into the ring buffer (otherwise known as sequences or cursors) are Java longs (64 bit signed numbers) and count upward forever. (Don&#8217;t panic &#8211; even at 1,000,000 messages per second, it would take the best part of 300,000 years to wrap around the sequence numbers).</li>
<li>These pointers are then &#8220;mod&#8217;ed&#8221; by the ring buffer size to figure out which array index holds the given entry. For performance, we actually force the ring buffer size to be the next power of two bigger than the size you ask for, and then we can use a simple bit-mask to figure out the array index.</li>
</ol>
<h3>Basic ring buffer structure</h3>
<p>WARNING: In terms of the organisation of the <a href="http://code.google.com/p/disruptor/" target="_blank">code</a>, much of what I&#8217;m about to say is a simplification. Conceptually, I think it&#8217;s simpler to understand starting from how I describe it.</p>
<p>The ring buffer maintains two pointers, &#8220;next&#8221; and &#8220;cursor&#8221;:</p>
<p><a href="http://blog.codeaholics.org/wp-content/uploads/2011/06/basic-structure.jpg?d7148e"><img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/basic-structure-300x135.jpg?d7148e" alt="" title="Basic Structure" width="300" height="135" class="aligncenter size-medium wp-image-158" /></a></p>
<p>In the picture above, a ring buffer of size 7 (hey, you know how these hand-drawn diagrams work out sometimes!) has slots 0 through 2 filled with data. The next pointer refers to the first free slot. The cursor refers to the last filled slot. In an idle ring buffer, they will be adjacent to each other as shown.</p>
<h3>Claiming a slot</h3>
<p>The Disruptor API has a transactional feel about it. You &#8220;claim&#8221; a slot in the ring buffer, then you write your data into the claimed slot, then you &#8220;commit&#8221; the data.</p>
<p>Let&#8217;s assume there&#8217;s a thread that wants to put the letter &#8220;D&#8221; into the ring buffer. It claims a slot. The claim operation is nothing more than a <a href="http://en.wikipedia.org/wiki/Compare-and-swap" target="_blank">CAS</a> &#8220;get-and-increment&#8221; operation on the next pointer. That is, this thread (let&#8217;s call it thread D) simply does an atomic get-and-increment which moves the next pointer to 4, and returns 3. Thread D has now claimed slot 3:<br />
<a href="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-d-claim.jpg?d7148e"><img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-d-claim-300x197.jpg?d7148e" alt="" title="After thread D claims a slot" width="300" height="197" class="aligncenter size-medium wp-image-160" /></a></p>
<p>Next, another thread (thread E) claims slot 4 in the same manner:</p>
<p><a href="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-e-claim.jpg?d7148e"><img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-e-claim-300x233.jpg?d7148e" alt="" title="After thread E claims a slot" width="300" height="233" class="aligncenter size-medium wp-image-163" /></a></p>
<h3>Committing the writes</h3>
<p>Now, threads D and E can both safely and simultaneously write their data into their respective slots. But let&#8217;s say that thread E finishes first for some reason&#8230;</p>
<p>Thread E attempts to commit its write. The commit operation consists of a CAS operation in a busy-loop. Since thread E claimed slot 4, it does a CAS waiting for the cursor to get to 3 and then setting it to 4. Again, this is an atomic operation. So, as the ring buffer stands right now, thread E is going to spin because the cursor is set to 2 and it (thread E) is waiting for the cursor to be at 3.</p>
<p>Now thread D commits. It does a CAS operation and sets the cursor to 3 (the slot it claimed) <a href="http://en.wikipedia.org/wiki/If_and_only_if" target="_blank">iff</a> the cursor is currently at 2. The cursor <i>is</i> currently at 2, so the CAS succeeds and the commit succeeds. At this point, cursor has been updated to 3 and all data up to that sequence number is available for reading.</p>
<p>This is an important point. Knowing how &#8220;full&#8221; the ring buffer is &#8211; i.e. how much data has been written, which sequence number represents the highest write, etc. &#8211; is purely a function of the cursor. The next pointer is only used for the transactional write protocol.</p>
<p><a href="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-d-commits.jpg?d7148e"><img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-d-commits-300x233.jpg?d7148e" alt="" title="After D commits" width="300" height="233" class="aligncenter size-medium wp-image-167" /></a></p>
<p>The final step in the puzzle is making thread E&#8217;s write visible. Thread E is still spinning trying to do an atomic update of the cursor from 3 to 4. Now the cursor is at 3, its next attempt will succeed:</p>
<p><a href="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-e-commits.jpg?d7148e"><img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/after-e-commits-300x233.jpg?d7148e" alt="" title="After thread E commits" width="300" height="233" class="aligncenter size-medium wp-image-169" /></a></p>
<h3>Summary</h3>
<p>The order that writes are visible is defined by the order in which threads claim slots rather than the order they commit their writes, but if you imagine these threads are pulling messages of a network messaging layer then this is really no different from the messages arriving at slightly different times, or the two threads racing to the slot claim in a different order.</p>
<p>So there we have it. It&#8217;s a pretty simple and elegant algorithm. (OK, I admit I was heavily involved in its creation!) Writes are atomic, transactional and lock-free, even with multiple writing threads.</p>
<p>(Thanks to Trish for the inspiration for the hand-drawn diagrams!)</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/quVAdd1quoA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/the-disruptor-lock-free-publishing/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/the-disruptor-lock-free-publishing/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-disruptor-lock-free-publishing</feedburner:origLink></item>
		<item>
		<title>Open sourcing the Disruptor</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/hjl7Ly7xDeQ/</link>
		<comments>http://blog.codeaholics.org/2011/open-sourcing-the-disruptor/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 09:14:37 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=130</guid>
		<description><![CDATA[LMAX recently&#160;open-sourced The Disruptor &#8211; one of the core frameworks upon which we build our ultra-high performance financial exchange. Today, we published a white paper detailing how The Disruptor works, and highlighting the sorts of performance benefits that can be achieved by using it. The Disruptor is essentially a library which we (and now you!) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lmax.com" target="_blank">LMAX</a> recently&nbsp;open-sourced <a href="http://code.google.com/p/disruptor/" target="_blank">The Disruptor</a> &#8211; one of the core frameworks upon which we build our ultra-high performance financial exchange. Today, we published a <a href="http://disruptor.googlecode.com/files/Disruptor-1.0.pdf" target="_blank">white paper</a> detailing how The Disruptor works, and highlighting the sorts of performance benefits that can be achieved by using it.</p>
<p>The Disruptor is essentially a library which we (and now you!) can use to do message passing within your application. If you like, it&#8217;s a queue on steroids. But this stuff is far more fascinating than just that for a number of reasons.<br />
<span id="more-130"></span></p>
<p>Firstly, the raw performance figures. Our testing shows that the latency you can achieve with The Disruptor is 3 orders of magnitude less than you can achieve with <tt>ArrayBlockingQueue</tt>. And with that, comes throughput that&#8217;s an order of magnitude higher! Win-win. But there&#8217;s more. The Disruptor actually goes <i>faster</i> under higher load. We&#8217;ve had this monster passing messages with latencies as low as <i>50ns</i>. That&#8217;s approaching the theoretical limit of what you can achieve with the hardware. Still think Java is slow?</p>
<p>Here&#8217;s a chart from the white paper, showing the relative latencies. It&#8217;s worth keeping in mind that this chart uses a log-log scale.<br />
<img src="http://blog.codeaholics.org/wp-content/uploads/2011/06/latency-histogram.png?d7148e" alt="Latency Histogram" title="latency-histogram" width="629" height="371" class="aligncenter size-full wp-image-147" /><br />
Secondly, the implementation approach. The Disruptor has been designed and built by stepping away from the problem, and re-evaluating it from a CS101 perspective. A lot of the principles used fly in the face of modern, main-stream concurrency ideas. For example, most deployments of The Disruptor will allow you pass messages from multiple producers to multiple consumers without a single lock. Not locking means not going to the kernel for lock arbitration, and that means no latency spikes.</p>
<p>Thirdly, the&nbsp;consistency. In our tests, <tt>ArrayBlockingQueue</tt> was giving us a mean latency of over 30,000ns, and a 99.99% tail of 4,000,000ns. The Disruptor was showing a mean latency of just 52ns, and a 99.99% tail of around 8,000ns. The consistency with which The Disruptor out-performs traditional queueing/message-passing techniques leads to less jitter and latency spikes. This is vital in a financial environment. Latency spikes lead to unhappy market makers who have no confidence in the prices they&#8217;re making. That leads to wider spreads. And that, ultimately, leads to unhappy customers.</p>
<p>Finally, you really have to hear <a href="http://www.infoq.com/presentations/LMAX" target="_blank">Martin Thompson</a> (our CTO) and <a href="http://skillsmatter.com/podcast/java-jee/how-to-do-100k-tps-at-less-than-1ms-latency" target="_blank">Mike Barker</a> (one&nbsp;of our tech leads) talk about this stuff to understand the passion that they put into its creation.</p>
<p>EDIT: Turns out Mike Barker has written a <a href="http://mikes-tech.blogspot.com/2011/06/disruptor-now-open-source.html" target="_blank">similar post</a> today!</p>
<p>EDIT 2: Also, Trisha Gee has <a href="http://mechanitis.blogspot.com/2011/06/dissecting-disruptor-whats-so-special.html" target="_blank">written a post</a> which goes into some of the basics about what a ring buffer is. Can you tell we&#8217;re all quite excited?</p>
<p>For more information, checkout the <a href="http://code.google.com/p/disruptor/" target="_blank">Google code</a> project and the <a href="http://disruptor.googlecode.com/files/Disruptor-1.0.pdf" target="_blank">white paper</a>.</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/hjl7Ly7xDeQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/open-sourcing-the-disruptor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/open-sourcing-the-disruptor/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=open-sourcing-the-disruptor</feedburner:origLink></item>
		<item>
		<title>The “single implementation” paradox – redux</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/9uFdezCkoxM/</link>
		<comments>http://blog.codeaholics.org/2011/the-single-implementation-paradox-redux/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 09:42:48 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=114</guid>
		<description><![CDATA[Following on from , my colleague, Adrian, has given the issue some thought and written an excellent post explaining his position. His conclusion is that we should simply not be marking classes as final because it really doesn&#8217;t bring any benefits. Even if you&#8217;re trying to follow Design by Extension, the next guy is just [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from <a href="http://blog.codeaholics.org/2011/the-single-implementation-paradox/">my previous post</a>, my colleague, Adrian, has given the issue some thought and written an <a href="http://www.symphonious.net/2011/06/18/the-single-implementation-fallacy/">excellent post</a> explaining his position.</p>
<p>His conclusion is that we should simply not be marking classes as final because it really doesn&#8217;t bring any benefits. Even if you&#8217;re trying to follow Design by Extension, the next guy is just going to remove the final keyword if it suits his purposes.</p>
<p>Sadly, I suspect he&#8217;s right. (Although there&#8217;s a conversation to be had here around collective code ownership, and assuming the last person did the best possible job. i.e. that final keyword is maybe there for a reason.)<br />
<span id="more-114"></span><br />
However, things get a lot less clear cut when dealing with libraries. Take, for example, Apache Ant. I&#8217;m writing a custom executor for Ant (<a href="http://blog.codeaholics.org/parallel-ant/">Parallel Ant</a>). I (mostly!) did the development on this project using TDD, but mocking out the Ant <tt>Project</tt> class so I could verify my interactions with it was, well, interesting. This particular class is not final, so the JMock <tt>ClassImposteriser</tt> should do the job nicely. However, some of the methods I wanted to call are marked final. So I&#8217;m back to square one. Only now, things are actually worse, because there&#8217;s no interface I can use in place of the class. So I can&#8217;t directly test my interactions with <tt>Project</tt> (or <tt>Target</tt> for that matter). </p>
<p>What&#8217;s particularly odd here is that across all of the methods on those two classes, there are only five final methods &#8212; three if your discount overloaded forms &#8212; and I wanted to call/mock two of them!</p>
<p>I think it&#8217;s pretty clear from looking at the <tt>Project</tt> class, that it is not expected to be extended. Of the <i>103</i> methods on this class, only four are marked final. One has to wonder why? Why those four and none of the others? This class is not designed for extension, but there is one subclass &#8212; <tt>MockProject</tt>, which lives in one of the unit tests. This is clearly a terrible smell.</p>
<p>But, smell aside, as a user of this library, what am I now supposed to do? The class is not final, so I can mock it. But I can&#8217;t intercept the methods I care about, because they <i>are</i> final. And there&#8217;s no interface to use as a proxy for the class. What I ended up doing, was writing a very simple class (<tt><a href="https://github.com/codeaholics/parallel-ant/blob/master/src/main/java/org/codeaholics/tools/build/pant/AntWrapperImpl.java">AntWrapper</a></tt>) which delegates to the various final methods. My code interacts with this class (via an interface! Sorry, Adrian!) and I can verify my interactions, etc. However, the <tt>AntWrapper</tt> class itself is still untestable. Hopefully, the trusty old <a href="http://en.wikipedia.org/wiki/Visual_inspection">Mk I Eyeball</a> should pick up bugs in this class.</p>
<p>I don&#8217;t feel like I&#8217;ve made progress here. If this was code I had collective ownership of, I&#8217;d probably just remove the final and move on. See, Adrian was right. But that&#8217;s still not really the right answer in my mind. </p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/9uFdezCkoxM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/the-single-implementation-paradox-redux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/the-single-implementation-paradox-redux/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-single-implementation-paradox-redux</feedburner:origLink></item>
		<item>
		<title>Parallel Ant 0.9 beta released</title>
		<link>http://feedproxy.google.com/~r/codeaholics-uk/~3/iaVr0VUtyLg/</link>
		<comments>http://blog.codeaholics.org/2011/parallel-ant-0-9-beta-released/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 20:44:16 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Build]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.codeaholics.org/?p=109</guid>
		<description><![CDATA[After almost a year with no work, Parallel Ant 0.9 beta is finally released. More info on the page.]]></description>
			<content:encoded><![CDATA[<p>After almost a year with no work, Parallel Ant 0.9 beta is finally released. More info on the <a href="http://blog.codeaholics.org/parallel-ant/">Parallel Ant</a> page.</p>
<img src="http://feeds.feedburner.com/~r/codeaholics-uk/~4/iaVr0VUtyLg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.codeaholics.org/2011/parallel-ant-0-9-beta-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.codeaholics.org/2011/parallel-ant-0-9-beta-released/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=parallel-ant-0-9-beta-released</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Database Caching 1/52 queries in 0.008 seconds using disk: basic
Object Caching 991/1102 objects using disk: basic

 Served from: blog.codeaholics.org @ 2013-05-15 10:46:12 by W3 Total Cache -->
