首页 文章

Erlang:分布式应用程序奇怪的行为

提问于
浏览
8

我用分布式的erlang应用程序付款 .

配置和想法取自:
http:/www.erlang.org/doc/pdf/otp-system-documentation.pdf 9.9. Distributed Applications

  • 我们有3个节点:n1 @ a2-X201,n2 @ a2-X201,n3 @ a2-X201

  • 我们有应用程序 wd 做一些有用的工作:)

配置文件:

  • wd1.config - 对于第一个节点:
[{kernel,
          [{distributed,[{wd,5000,['n1@a2-X201',{'n2@a2-X201','n3@a2-X201'}]}]},
           {sync_nodes_mandatory,['n2@a2-X201','n3@a2-X201']},
           {sync_nodes_timeout,5000}
        ]}
      ,{sasl, [
      %% All reports go to this file
      {sasl_error_logger,{file,"/tmp/wd_n1.log"}}
      ]
    }].

第二个

  • wd2.config:
[{kernel,
        [{distributed,[{wd,5000,['n1@a2-X201',{'n2@a2-X201','n3@a2-X201'}]}]},
         {sync_nodes_mandatory,['n1@a2-X201','n3@a2-X201']},
         {sync_nodes_timeout,5000}
         ]
     }
    ,{sasl, [
        %% All reports go to this file
        {sasl_error_logger,{file,"/tmp/wd_n2.log"}}
    ]
    }].
  • 对于节点n3看起来类似 .

现在在3个独立的终端启动erlang:

  • erl -sname n1 @ a2-X201 -config wd1 -pa $ WD_EBIN_PATH -boot start_sasl

  • erl -sname n2 @ a2-X201 -config wd2 -pa $ WD_EBIN_PATH -boot start_sasl

  • erl -sname n3 @ a2-X201 -config wd3 -pa $ WD_EBIN_PATH -boot start_sasl

在每个erlang节点上启动应用程序:* application:start(wd) .

(n1@a2-X201)1> application:start(wd).

=INFO REPORT==== 19-Jun-2011::15:42:51 ===
wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$" 
ok
(n2@a2-X201)1> application:start(wd).
ok
(n2@a2-X201)2>
(n3@a2-X201)1> application:start(wd).
ok
(n3@a2-X201)2>

一切都好的 . 正如在Erlang文档中所写:应用程序在节点 n1@a2-X201 运行

现在kill节点 n1 :应用程序已迁移到 n2

(n2@a2-X201)2> 
=INFO REPORT==== 19-Jun-2011::15:46:28 ===
wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$"

继续我们的游戏:kill node n2 再一次系统工作正常 . 我们在节点 n3 有我们的应用程序

(n3@a2-X201)2> 
=INFO REPORT==== 19-Jun-2011::15:48:18 ===
wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$"

现在恢复节点 n1n2 . 所以:

Erlang R14B (erts-5.8.1) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.1  (abort with ^G)
(n1@a2-X201)1> 

Eshell V5.8.1  (abort with ^G)
(n2@a2-X201)1>

节点 n1n2 又回来了 .
看起来现在我必须手动重启应用程序:*首先在节点 n2 执行:

(n2@a2-X201)1> application:start(wd).
  • 看起来像是绞死了......

  • 现在重启 n1

(n1@a2-X201)1> application:start(wd).

=INFO REPORT==== 19-Jun-2011::15:55:43 ===
wd_plug_server starting... PluginId: 4 Path: "/home/a2/src/erl/data/SIG" FileMask: "(?i)(.*)\\.SIG$" 

ok
(n1@a2-X201)2>

有用 . 并且节点 n2 也已返回OK:

Eshell V5.8.1  (abort with ^G)
(n2@a2-X201)1> application:start(wd).
ok
(n2@a2-X201)2>

在节点 n3 ,我们看到:

=INFO REPORT==== 19-Jun-2011::15:55:43 ===
    application: wd
    exited: stopped
    type: temporary

通常,除了在节点 n2 处启动应用程序的延迟之外,一切看起来都不错,如文档中所述 .

现在再次杀死节点 n1

(n1@a2-X201)2> 
User switch command
 --> q
[a2@a2-X201 releases]$

行动......一切都挂了 . 应用程序未在另一个节点重新启动 .

实际上,当我写这篇文章时,我意识到有时候一切都好了,有时候我有问题 .

任何想法,虽然恢复“主要”节点时可能会出现问题并再次杀死它?

2 回答

  • 1

    explained over at Learn You Some Erlang(滚动到底部),分布式应用程序仅在作为发布的一部分启动时才能正常工作,而不是在使用 application:start 手动启动它们时 .

  • 0

    您可能会看到很奇怪,您可能会完全在节点n1 / n2上重新启动应用程序,而n3仍然在初始应用程序初始化下运行 .

    如果您的应用程序启动任何系统范围的进程并使用它们的pid而不是使用设置为global,pg或pg2的注册名称,那么您可能正在使用两组全局状态 .

    如果是这种情况,建议采用的方法是专注于从现有应用程序添加/删除节点,而不是重新启动整个应用程序 . 这样,节点就会离开并加入到一组现有的初始化值中 .

相关问题