Does hot code-swapping come for free?

In general when a hot-swap is performed:

  1. The new code is loaded into the system, processes with old code keep running unless a another new version is loaded, then any processes with the old code are killed (and reloaded if in the supervision tree), the system supports 2 code versions per module at a time.
  2. A process that has its code reloaded gets a system message sent to it telling that, the OTP behaviours (like GenServer) will handle that by calling your code_change function then swapping to the new code. If non-OTP you can handle that message by calling your loop function via a long call (Module.myloop instead of just myloop) to swap to the new code (while doing whatever conversions you want one way or another). The Module.blah form always calls the new code of a module. The blah form calls the local version of the code of a module (take in to account Elixir imports, those are long calls).
  3. And of course old versions can keep running too if they want, they will just be killed if they get more than one version out of date (of which a supervisor should recreate them if in a supervision tree). :slight_smile:
7 Likes