erlang - 我可以使用模块池来决定负载平衡吗?

标签 erlang

我正在寻找一种自动执行负载平衡的方法,这个模块吸引了我。

正如手册所说,

pool can be used to run a set of Erlang nodes as a pool of computational processors. It is organized as a master and a set of slave nodes and includes the following features:

  • The slave nodes send regular reports to the master about their current load.
  • Queries can be sent to the master to determine which node will have the least load.

The BIF statistics(run_queue) is used for estimating future loads. It returns the length of the queue of ready to run processes in the Erlang runtime system.

从节点定期发送报告的频率和负载是多少?

这样的负载均衡方式是否正确?

最佳答案

报告发送every 2 seconds并使用从 statistics(run_queue) 收集的信息来确定负载最少的节点。 run_queue 返回当前节点调度程序的队列大小。

当您调用 pool:get_node/0 时,您将获得等待在其调度程序上执行的任务数量最少的节点。请记住,节点是按排序顺序保存的,因此调用 pool:get_node/0 不会直接查询节点,而是依赖可能长达 2 秒的信息。

如果您需要一个负载均衡的节点池,pool 非常有用。

这里有一些来自 pool.erl 源的更多信息:

%% Supplies a computational pool of processors.
%% The chief user interface function here is get_node()
%% Which returns the name of the nodes in the pool
%% with the least load !!!!
%% This function is callable from any node including the master
%% That is part of the pool
%% nodes are scheduled on a per usgae basis and per load basis,
%% Whenever we use a node, we put at the end of the queue, and whenever
%% a node report a change in load, we insert it accordingly

关于erlang - 我可以使用模块池来决定负载平衡吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15456897/

相关文章:

concurrency - 如果在发出进程 pid 之前向进程发送消息,是否保证首先收到该消息?

erlang - 编译并运行 Yaws appmod

erlang - Elixir 紧循环加速

erlang - Erlang 中的列表右旋转

ssl - Erlang ssl 请求的负载均衡

ssl - TLS - 通常在哪里为 MQTT 代理执行 tls 握手?

concurrency - Erlang中的并发及其适当的工作流程

inheritance - Erlang 类型定义

erlang - 如何将节点添加到 mnesia 集群?

erlang - 如何在 Erlang/OTP 中将主管的 child pid 共享给另一个 child