Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://www.process-one.net/en/ejabberd/" rel="noreferrer">ejabberd</a> is one of the most well know erlang application and the one I learnt erlang with.</p> <p>I think it's the one of most interesting project for learning erlang because it is really building on erlang's strength. (However some will argue that it's not OTP, but don't worry there's still a trove of great code inside...)</p> <p><strong>Why ?</strong></p> <p>An XMPP server (like ejabberd) can be seen as a high level router, routing messages between end users. Of course there are other features, but this is the most important aspect of an instant messaging server. It has to route many messages simultaneously, and handle many a lot of TCP/IP connections.</p> <p>So we have 2 features:</p> <ul> <li>handle many connections</li> <li>route messages given some aspects of the message</li> </ul> <p>These are examples where erlang shines.</p> <p><strong>handle many connections</strong></p> <p>It is very easy to build scalable non-blocking TCP/IP servers with erlang. In fact, it was designed to solve this problem. And given it can spawn hundreds of thousand of processes (and not <em>threads</em>, it's a share-nothing approach, which is simpler to design), ejabberd is designed as a set of erlang processes (which can be distributed over several servers) :</p> <ul> <li>client connection process</li> <li>router process</li> <li>chatroom process</li> <li>server to server processes</li> </ul> <p>All of them exchanging messages.</p> <p><strong>route messages given some aspects of the message</strong></p> <p>Another very lovable feature of erlang is <a href="http://en.wikibooks.org/wiki/Erlang_Programming/Pattern_Matching" rel="noreferrer">pattern matching</a>. It is used throughout the language.</p> <p>For instance, in the following :</p> <pre><code>access(moderator, _Config)-&gt; rw; access(participant, _Config)-&gt; rw; access(visitor, #config{type="public"})-&gt; r; access(visitor, #config{type="public_rw"})-&gt; rw; access(_User,_Config)-&gt; none. </code></pre> <p>That's 5 different versions of the <code>access</code> function. Erlang will select the most appropriate version given the arguments received. (<code>Config</code> is a structure of type <code>#config</code> which has a <code>type</code> attribute).</p> <p>That means it is very easy and much clearer than chaining <code>if/else</code> or <code>switch/case</code> to make business rules.</p> <p><strong>To wrap up</strong></p> <p>Writing scalable servers, that's the whole point of erlang. Everything is designed it making this easy. On the two previous features, I'd add :</p> <ul> <li>hot code upgrade</li> <li><a href="http://www.erlang.org/doc/apps/mnesia/index.html" rel="noreferrer"><code>mnesia</code></a>, distributed relational database (included in the base distribution)</li> <li><a href="http://code.google.com/p/mochiweb/" rel="noreferrer"><code>mochiweb</code></a>, on which most http erlang servers are built on</li> <li>binary support (decoding and encoding binary protocol easy as ever)</li> <li>a great community with great open source projects (<code>ejabberd</code>, <code>couchdb</code> but also <a href="http://bitbucket.org/justin/webmachine/wiki/Home" rel="noreferrer"><code>webmachine</code></a>, <a href="http://riak.basho.com/" rel="noreferrer"><code>riak</code></a> and a slew of library very easy to embed)</li> </ul> <p><strong>Fewer LOCs</strong></p> <p>There is also <a href="http://www.metabrew.com/article/rewriting-playdar-c-to-erlang-massive-savings/" rel="noreferrer">this article</a> from Richard Jones. He rewrote an application from C++ to erlang: 75% fewer lines in erlang.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload