Reputation: 132
What is a difference between simple_one_for_one
and one_for_one
restart strategies? When need to prefer one over another?
Upvotes: 2
Views: 556
Reputation: 1107
Let supervisor denoted by S
, workers denoted by W
.
If S
supervises W1
, W2
, W3
under one_for_one
restart strategy, and any of W
dies, only that W
is restarted.
simple_one_for_one
restart strategy is same as one_for_one
. Meaning if one W
dies only that W
is restarted. Only difference is when S
starts, it does not have any W
s.
W
s are added dynamically by calling supervisor:start_child/2
.
When need to prefer one over another?
simple_one_for_one
— You need a W
to serve something per request basis; e.g.: authentication protocols
one_for_one
— You need dedicated W
processes to be there no matter what, throughout your application life cycle.
Upvotes: 7