User590254
User590254

Reputation: 132

Erlang supervisor: difference between simple_one_for_one and one_for_one restart strategies

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

Answers (1)

Kalpa Gunarathna
Kalpa Gunarathna

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.

one for one

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 Ws.

Ws 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

Related Questions