I'm doing a tutorial and it says "In this guide, we will learn how to build a complete Elixir application, with its own supervision tree, configuration, tests and more".
In plain english, what is a supervision tree in Elixir?
Thanks!
I'm doing a tutorial and it says "In this guide, we will learn how to build a complete Elixir application, with its own supervision tree, configuration, tests and more".
In plain english, what is a supervision tree in Elixir?
Thanks!
In Erlang and Elixir applications, structure is imposed by having a top-level "supervisor" processes which starts the other processes in your application. Those other processes can include other supervisors, which also have their own children, and this recursive structure takes the shape of a tree, hence "supervision tree". Supervision of processes is what gives Erlang/Elixir it's fault tolerance features, as failure is isolated to some branch of the tree, where the supervisor of that branch can either restart the failed children, or allow itself to fail as well, bubbling the failure up to the next highest supervisor in the tree.
Since you have tagged Erlang, I will answer this Erlang's perspective. But again Erlang, Elixir its pretty much the same thing.
Erlang is a concurrency oriented programming language. Meaning its built ground up to deal with concurrency. One main feature especially needed in telecommunication/protocol related applications. Almost every programming language has a mechanism to deal with concurrent operations.
So for example,
Actor model in plain English
In actor model we have 2 types of processes.
Basically supervisors are there to supervise worker processes. That's it. If we want to create a worker process to carry out some work we ask supervisor create it for us. In case of the worker dies, the supervisor will restart it for you. You dont need to worry about the well being of the worker process. Furthermore supervisors can other supervisors also.
Worker processes are there to perform some tasks. That's it. It will perform whatever the tasks it is assigned and just die. In case it dies/crash due to a a not normal reason, its supervisor will restart the worker process to carry out its intended task.
So overall we can hav a root supervisor(call it S0) manage 2 supervisors S1, S2. S2 manages another supervisor S3. S3 supervises 5 workers processes namely W1-W5. This whole hierarchy is the supervision tree in Erlang/Elixir.
Here is an example supervision tree in a RADIUS protocol related project. https://github.com/sigscale/radierl/blob/master/doc/supervision.png
There is bunch of more stuff related to actor model like message passing etc. This will be good place to get an idea about actor model.
© 2022 - 2024 — McMap. All rights reserved.