Home > Erlang > Why I Love Erlang

Why I Love Erlang

Haven’t written in a while… been busy at work and my hobby project. This weekend I realized why I love Erlang… you don’t really understand the strength of Erlang until you have worked on heavy loaded live systems which need immediate attention.

I’m currently involved in a project which has a lot of subscribers. I can’t go into any details (NDA) but I can say this; We had a problem where one of our applications somewhere in the cluster would go down and not bounce back properly (very simple explanation of the problem :))

Anyway, we fixed a problem and got clearance to patch it and then went home. During the evening I wanted to check if the system was behaving, fortunately I could access the site from home. 4 logins later and a lot of SSH:ing and RSA keys and Personal codes I logged on to the shell… that’s when I realized that for me to check what I wanted to check on each node would be incredibly tedious since I would have to go through the connection procedure if I wanted to monitor everything at the same time OR I would have to disconnect and connect to another node OR I would have to RPC individually to each node I wanted to check.

Well anyway… after 3 seconds of thinking I just opened my text editor and wrote this:

ChkApp = fun(App) ->
  lists:map(fun(Node) ->
    case rpc:call(Node, application, which_applications, []) of
      {bad_rpc, Reason} ->
        {Node, Reason};
      Apps ->
        {Node, lists:keymember(App, 1, Apps)}
  Cluster) end.

Copy/Paste into the shell and then just run…

x> ChkApp(my_application).
[{'node1@', true},
 {'node2@', true},
 {'node3@', true}].

After you are done… monitoring/working just f(ChkApp). Done.

This maybe doesn’t look like much, but think about it…

  1. You can in a very easy way run a command on another node and get it back in Erlang terms.
  2. You can define Funs and run them how ever you want, you can even nest Funs and build up monitor/introspection tools on the fly
  3. There is no XML or complicated/tedious setup you have to make to call other nodes… you just… well… rpc:call them 🙂

Now a note of caution; Doing these sort of things on a Live system is very sensitive… be careful but I do have a golden rule I have set for myself: As long as you only read and don’t write data, then you are fine.

I was just sitting an imagining trying to do this in Java… and a big relief hit me…

It is these small things that make me love Erlang.

Categories: Erlang Tags:
  1. Abdul Fattah
    2009/10/31 at 07:54

    It’s a Nice way of monitoring, I like it 🙂

  2. 2009/11/12 at 16:28

    I’m rather new to erlang but I continue to be impressed with how concise it can be. This is another example of how a functional language with strength in set-based operations and a batteries-included design philosophy can make our lives easier.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: