Sergei Basharov
Sergei Basharov

Reputation: 53850

Erlang Hot Code Swapping vs interpreted languages

The feature widely advertised about Erlang is its ability to hot-swap code modules while the app is running and is shown as a unique killer-feature not available in other languages.

Here is a quote from Joe Armstrong's book:

Most servers execute a fixed program, and if you want to modify the behavior of the server, you have to stop the server and then restart it with the modified code.

Though, in context of web development, the majority of languages support so-called hot-swapping of the code even without calling it so. It's just updating code and publishing it on the web via git or a continuous integration solution.

I know Erlang has a lot of applications in domains other than web, so I am sure it makes sense in those cases.

But, does this feature have benefits in comparison to dynamic languages used for web, like Python, Ruby, JavaScript? What are the cases for web development where it outperforms popular web-oriented languages?

Upvotes: 0

Views: 590

Answers (2)

Pascal
Pascal

Reputation: 14042

The hot code swaping in erlang offers more than the ability to upgrade the code (I won't make any comparison with python, ruby or javascript, I have a very limited knowledge of them):

  • You can decide, for each node, when you will load a new version of code
  • Then 2 versions of code will be present in the VM, all the running processes will use the old version of each module until a next fully qualified call to this module occurs (Mod:Func/arity)
  • if you are using OTP behaviors, the server (or fsm or gen_event) will be called first with their code_change call_back, receiving in the parameters, the old version of the module. So it is possible to check either or not it is possible to manage the upgrade, and to perform any necessary operation on the state Data, ETS, process synchronization... before really jumping into the new code.
  • if you are not using OTP behavior, it is still possible to receive the messages of the form {system, From, Req} and then call sys:handle_system_msg/6 which in turn will call the code_change call_back.

Upvotes: 3

Paul Peregud
Paul Peregud

Reputation: 347

This feature is not targeted at web development just as Erlang itself was not created with web development specifically in mind.

One possible area where this feature outperforms model used in general dynamic languages used for web is precise control over the way code is upgraded.

  • code can be updated not only between calls, but also during call
  • you can provide explicit path of upgrade for state related to call

Upvotes: 0

Related Questions