如何在分布式 Erlang 中的所有节点上编码加载模块?
How to code load modules on all nodes in Distributed Erlang?
我正在学习Erlang/OTP,在第14章中说:
"you can load Module to all nodes use shell command : command nl(Mod)
".
我想知道,怎么办?我找不到 shell 命令:command nl(Mod)
.
您尝试在 shell 中键入 help().
?这个函数定义在 stdlib 的 c module 中。但是shell会理解nl(Mod).
要执行测试,至少启动两个 erlang 虚拟机并连接它:
erl -pa your_module_path -name first@127.0.0.1
erl -name second@127.0.0.1
在第一个 shell 中通过以下方式连接到第二个节点:
net_kernel:connect('second@127.0.0.1').
应该用 true
来回应。
在 your_module_path
中创建一些简单的模块,例如:
-module(nl_test).
-export([test/0]).
test() -> 1.
并通过 c(nl_test).
编译现在你可以从第一个 shell 运行 nl_test:test()
但第二个无法加载它。要广播它并强制加载,只需从第一个 运行 nl(nl_test).
现在尝试从第二个 shell nl_test:test()
.
假设您将 test() -> 1.
修改为 test() -> 2.
,您需要做的只是 运行 c(nl_test), nl(nl_test).
或更短的 nc(nl_test)
,这意味着相同.
nl_test:test().
在所有连接的节点上应该 return 2
.
这可能看起来很简单,但在复杂的生产系统中,适当的热加载是一个相当高级的问题。
我正在学习Erlang/OTP,在第14章中说:
"you can load Module to all nodes use shell command :
command nl(Mod)
".
我想知道,怎么办?我找不到 shell 命令:command nl(Mod)
.
您尝试在 shell 中键入 help().
?这个函数定义在 stdlib 的 c module 中。但是shell会理解nl(Mod).
要执行测试,至少启动两个 erlang 虚拟机并连接它:
erl -pa your_module_path -name first@127.0.0.1
erl -name second@127.0.0.1
在第一个 shell 中通过以下方式连接到第二个节点:
net_kernel:connect('second@127.0.0.1').
应该用 true
来回应。
在 your_module_path
中创建一些简单的模块,例如:
-module(nl_test).
-export([test/0]).
test() -> 1.
并通过 c(nl_test).
编译现在你可以从第一个 shell 运行 nl_test:test()
但第二个无法加载它。要广播它并强制加载,只需从第一个 运行 nl(nl_test).
现在尝试从第二个 shell nl_test:test()
.
假设您将 test() -> 1.
修改为 test() -> 2.
,您需要做的只是 运行 c(nl_test), nl(nl_test).
或更短的 nc(nl_test)
,这意味着相同.
nl_test:test().
在所有连接的节点上应该 return 2
.
这可能看起来很简单,但在复杂的生产系统中,适当的热加载是一个相当高级的问题。