elixir - 集群中的全局动态主管
问题描述
我有一个独特的问题,我不需要在 elxir 中解决。
我需要使用动态主管在集群环境中动态启动 (n) 个子级。我正在使用 libcluster 来管理集群并使用全局进程注册表来查找动态主管 pid。这是正在发生的事情:
global: Name conflict terminating {:packer_supervisor, #PID<31555.1430.0>}
这是主管的代码:
defmodule EcompackingCore.PackerSupervisor do
use DynamicSupervisor
require Logger
def start_link() do
DynamicSupervisor.start_link(__MODULE__, :ok, name: {:global, :packer_supervisor})
end
def init(:ok) do
Logger.info("Starting Packer Supervisor")
DynamicSupervisor.init(strategy: :one_for_one)
end
def add_packer(badge_id, packer_name) do
child_spec = {EcompackingCore.Packer, {badge_id, packer_name}}
DynamicSupervisor.start_child(:global.whereis_name(:packer_supervisor), child_spec)
end
def remove_packer(packer_pid) do
DynamicSupervisor.terminate_child(:global.whereis_name(:packer_supervisor), packer_pid)
end
def children do
DynamicSupervisor.which_children(:global.whereis_name(:packer_supervisor))
end
def count_children do
DynamicSupervisor.count_children(:global.whereis_name(:packer_supervisor))
end
end
问题似乎是在两个节点上都启动了主管。处理这个问题的最佳方法是什么?我真的需要主管是动态的,这样我才能有效地管理工作模块。可能是不同的注册表?
谢谢你的帮助。
解决方案
经过一番研究,我找到了一个解决方案:
我现在使用https://github.com/bitwalker/swarm来处理 pid 注册。这允许跨集群设置进程,并在其中一个节点出现故障时提供切换支持。
推荐阅读
- python - 移动和写入图像的像素-Python-
- python - 为什么列表的此代码对于大型条目会失败?
- java - 泛型继承常见误区
- pandas - pandas:如何在时间序列中选择“迄今为止最大”的行?
- node.js - MongoDb Atlas 未连接到 Heroku
- python-3.x - Django 如何创建 Pip 和 Piplock 文件?
- javascript - OnClick 功能不会在
- swift - 在 Swift 上发出多个网络请求
- python - 将对称 Pandas 数据框中的索引、列和值分成三个不同的列,不重复
- php - 基于 WooCommerce 购物车中某个类别的商品数量的折扣