Nuno_Coletiv
Nuno_Coletiv

Reputation: 367

Difference between Supervisor and DynamicSupervisor

Someone can explain difference between Supervisor and DynamicSupervisor in Elixir?

Upvotes: 4

Views: 1216

Answers (2)

Cyzanfar
Cyzanfar

Reputation: 7146

A DynamicSupervisor is a supervisor designed to supervise and manage many children dynamically.

This is the main purpose of a DynamicSupervisor-- you can read the full proposal on Github

At a high level here are the four main goals outlined in the proposal:

  • Simplify the API and usage of both Supervisor modules. Most of the documentation in the Supervisor module is full of conditionals: "if the supervisor type is :simple_one_for_one, it will behave as X, otheriwse as Y." The differences in behaviour with little surrounding context makes supervisors hard to learn, understand and use;
  • Provide out-of-the-box supervisor sharding for cases where the supervisor itself may be a scalability concern;
  • Provide a built-in registry to avoid developers unecessarily using dependencies like gproc or incorrect dependencies like global;
  • Implement the GenStage specification so dynamic supervisors can subscribe to producers and spawn children dynamically based on demand;

Upvotes: 6

Related Questions