Supervisor 和 DynamicSupervisor 的区别

Difference between Supervisor and DynamicSupervisor

有人可以解释一下 Elixir 中 Supervisor 和 DynamicSupervisor 的区别吗?

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

这是 DynamicSupervisor 的主要目的——您可以阅读完整的 proposal on Github

这里是提案中概述的四个主要目标:

  • 简化两个 Supervisor 模块的 API 和使用。最多 Supervisor 模块中的文档充满了 条件:“如果主管类型是:simple_one_for_one, 它将表现为 X,否则表现为 Y。” 周围环境很少的行为使主管 难以学习、理解和使用;
  • 为以下情况提供 out-of-the-box 主管分片 主管本身可能是一个可扩展性问题;
  • 提供一个built-in注册表,避免开发者不必要的 使用 gproc 之类的依赖项或不正确的依赖项,例如 全球;
  • 实施 GenStage 规范 所以动态监管者可以订阅生产者和产卵 children 动态根据需求;

另一个解释很有趣

https://blog.carbonfive.com/2018/01/30/comparing-dynamic-supervision-strategies-in-elixir-1-5-and-1-6/