A script for running an erlang application as a service on a user

As a newbie erlanger I had to deploy my first application into production some time ago. Also it had to be run by a specific user. I am way too far from knowing what there is to know about erlang releases, so I have come up with some quick solution in the meantime. Maybe you beginner can also find it useful

The first element is a shell script. I am using it for running several application instances with different names, hence the second parameter in Usage: $0 {start|stop|debug} appname. I think you can easily grab the idea behind it and apply that to your own application

Read more →


gen_server behaviour, synchronous vs asynchronous

gen_server:handle_call vs gen_server:handle_cast

Now that you have a clear idea of what a basic gen_server is, I would like to take a closer look at the differences between gen_server:handle_cast/2 and gen_server:handle_call/3. It is a very simple thing to learn if you get the right example.

Synchronous communication with call

If your client requires a server response to continue its activity you will likely have to invoke the gen_server:call function. This way the client will wait for the server gen_server:handle_call/3 to complete its processing, most likely because the client will consume the server response in some way. This is synchronous communication. The consequences are obvious, a server receiving many calls will block clients waiting to get service.

Read more →


Erlang/OTP gen_server template example

Erlang/OTP, what is this?

Erlang is a functional programming language, process oriented, designed for performance in concurrent and distributed scenarios. OTP (standing for Open Telecom Platform) is a framework written for erlang. A framework is some code someone wrote, hopefully with good design patterns in mind to avoid reinventing the wheel every time. This is the case, the OTP framework was written to encourage good patters and robustness

OTP behaviours

Erlang behaviours are erlang’s way to abstract common patterns. Basically there are two modules, the behaviour itself with all the common functions, and the callback module, including the specific functionality that process provides by implementing the behaviour callbacks

There are basically four OTP behaviours you must know if you plan to write some quality erlang process modules

Read more →