Erlang is a programming language written with two principles in mind: “Errors will ALWAYS occur” and “The system must NEVER go down”.
These two add up to the philosophy of keeping the processes in larger structures isolated, the structures themselves easy to recover and general rules of action simple. One of the features that enables developers create systems with minimal downtime is the hot code loading/swapping facilities available in the runtime system.
Erlang supports change of code in a running system. Code replacement is done on module level.
The code of a module can exist in two variants in a system: current and old. When a module is loaded into the system for the first time, the code becomes ‘current’. If then a new instance of the module is loaded, the code of the previous instance becomes ‘old’ and the new instance becomes ‘current’. Both old and current code is valid, and may be evaluated concurrently.
If a third instance of the module is loaded, the code server will remove (purge) the old code and any processes lingering in it will be terminated. Then the third instance becomes ‘current’ and the previously current code becomes ‘old’.
Feuerlabs, one of our partners in the embedded domain, recently published a YouTube video demonstrating this language feature alongside their Exosense framework, upgrading the flight control system of an AR Drone while in the air. You can find the video embedded below or by clicking this link.
Interested in learning more about Erlang? Join part two of our series of “Learning Erlang – Easier than you think” webinar by Robert Virding (one of the co-creators of the Erlang programming language) and Francesco Cesarini (O’Reilly author and Technical Director at Erlang Solutions) on Nov 13 (Wednesday) at 6:00 PM GMT! More information available at this link.