Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code hot swapping in Erlang

I recently saw a video about Erlang on InfoQ, In that video one of the creators presented how to replace the behavior of a message loop.

He was simply sending a message containing a lambda of the new version of the message loop code, which then was invoked instead of calling the old loop again.

Is that code hot swapping in Erlang reffers to? Or is that some other more native feature?

like image 948
Roger Johansson Avatar asked Jun 03 '10 19:06

Roger Johansson


1 Answers

Yes, hot swapping in erlang servers generally refers to this feature. It is well explained in the stackoverflow question Achieving code swapping in Erlang’s gen_server, and also in this neat Erlang Generic Server tutorial or this little one.

The Erlang/OTP gen_server module provides a generic way to achieve hot swapping, by implementing a Module:code_change/3 function in the callback module.

This way, you can upgrade a servers code without shutting it down, or fall back to former implementation if something does not work as expected. In general, hot swap should be put in place using the generic release handler.

like image 113
tonio Avatar answered Oct 11 '22 07:10

tonio