<?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>Chris Chandler &#187; Erlang</title>
	<atom:link href="http://chrischandler.name/category/erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrischandler.name</link>
	<description>Squandering time as a raving egomaniac</description>
	<lastBuildDate>Thu, 03 Jun 2010 23:16:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>basic erlang clustering</title>
		<link>http://chrischandler.name/erlang/basic-erlang-clustering/</link>
		<comments>http://chrischandler.name/erlang/basic-erlang-clustering/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 23:34:10 +0000</pubDate>
		<dc:creator>Chris Chandler</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[clustering]]></category>
		<category><![CDATA[magic cookie]]></category>
		<category><![CDATA[nodes]]></category>

		<guid isPermaLink="false">http://chrischandler.name/?p=27</guid>
		<description><![CDATA[Clustering is one of the most compelling reasons to use Erlang.  Take a look at this basic example showing what it takes to connect multiple Erlang nodes to distribute work.]]></description>
			<content:encoded><![CDATA[<p>One of the strongest reasons to consider <a title="Erlang" href="http://chrischandler.name/erlang">Erlang</a> for a programming project is concurrency.  Erlang makes concurrency and distributed work dead simple.</p>
<p>If you have two nodes, <em>nodex</em> and <em>nodey</em> , and you want to be able to do something on both you can start the Erlang shell on nodex with the following:</p>
<pre>erl -setcookie someFormOfPreSharedSecret -name nodex</pre>
<p>and a similar command on nodey</p>
<pre>erl -setcookie someFormOfPreSharedSecret -name nodey</pre>
<p>The key here is to make sure that both nodes have the same magic cookie value, otherwise they won&#8217;t be able to communicate.</p>
<p>From nodex issue <em>net_adm:ping(&#8216;nodey@your_domain_here.com&#8217;)</em>.  If the connection was successful you&#8217;ll see the result pong, if something didn&#8217;t go right, you&#8217;ll see pang.  From this point, you can run:</p>
<pre>nodes().</pre>
<p>and see every node your currently connected with.</p>
<p>Now for the magic, let&#8217;s say you want to start a particular task running on all of your nodes.  We&#8217;re going to achieve this by using the lists:foldl function:</p>
<p><script src="http://gist.github.com/155217.js"></script> Foldl takes 3 arguments: an anonymous function to call for every element of the third parameter, an accumulator to pass to the anonymous function, and the the list of things to iterate over.  If your more familiar with Ruby this would hypothetically look like:  <script src="http://gist.github.com/155225.js"></script></p>
<p>The key difference being Ruby doesn&#8217;t return Pids to later refer back to those concurrent processes we started.</p>
<p>After running the Erlang example every node will run io:format and print a simple message.  That&#8217;s really all there is to distributing Erlang processing power.  By retaining a list of the remote Pids you can do neat tricks with firing up a good number of initial processes and then sending them subsequent messages.  I&#8217;ll make a valiant effort to write about this more.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrischandler.name/erlang/basic-erlang-clustering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
