0

1 つの erlang アプリケーションで webmachine の 2 つのインスタンスを作成しようとしています。各インスタンスは異なるポートで実行され、固有の構成があります。ここの webmachine doc に従って、スーパーバイザーの仕様 (application_sup.erl) で開始する次のプロセスを追加しました。

 {
    webmachine_instance_1,
    { webmachine_mochiweb, start, 
       [
          [
              { ip, "0.0.0.0"},
              { port, 8000},
              { dispatch, [ {["*"], file_resource, []} ] }
          ] 
        ]
    },
    permanent,
    5000,
    worker,
    dynamic
 },
 {
    webmachine_instance_2,
    { webmachine_mochiweb, start, 
       [
          [
              { ip, "0.0.0.0"},
              { port, 8080},
              { dispatch, [ {["*"], file_resource, []} ] }
          ] 
       ]
    },
    permanent,
    5000,
    worker,
    dynamic
 }

両方のインスタンスを含めると、開始エラーが発生し、erlang アプリケーションを開始できません。webmachine の 1 つのインスタンス (webmachine_instance_1 または webmachine_instance_2) でアプリケーションを実行しようとしただけで、アプリケーションは正常に起動します。

特定のエラーは次のとおりです。

=PROGRESS REPORT==== 11-Mar-2014::17:00:31 ===
      supervisor: {local, application_sup}
         started: [{pid,<0.230.0>},
                   {name,webmachine_instance_1},
                   {mfargs,
                       {webmachine_mochiweb,start,
                           [[{ip,"0.0.0.0"},
                             {port,8000},
                             {dispatch, [{['*'],
                                   file_resource,
                                   []
                             }]}]
                            ]
                        }
                   },
                   {restart_type,permanent},
                   {shutdown,5000},
                   {child_type,worker}] 

 =SUPERVISOR REPORT==== 11-Mar-2014::17:00:31 ===
     Supervisor: {local, application_sup}
     Context:    start_error
     Reason:     {'EXIT',
                 {undef,
                     [{webmachine_mochiweb,start,
                          [{ip,"0.0.0.0"},
                           {port,8080},
                           {dispatch,[{["*"],file_resource,[]}]}],
                          []},
                      {supervisor,do_start_child,2,
                          [{file,"supervisor.erl"},{line,303}]},
                      {supervisor,start_children,3,
                          [{file,"supervisor.erl"},{line,287}]},
                      {supervisor,init_children,2,
                          [{file,"supervisor.erl"},{line,253}]},
                      {gen_server,init_it,6,
                          [{file,"gen_server.erl"},{line,304}]},
                      {proc_lib,init_p_do_apply,3,
                          [{file,"proc_lib.erl"},{line,227}]}]}}
 Offender:   [{pid,undefined},
              {name,webmachine_instance_2},
              {mfargs,
                  {webmachine_mochiweb,start,
                      [{ip,"0.0.0.0"},
                       {port,8080},
                       {dispatch,[{["*"],file_resource,[]}]}]}},
              {restart_type,permanent},
              {shutdown,5000},
              {child_type,worker}]

私は erlang にかなり慣れていないため、ここでの根本的な問題をよく理解していない可能性があります。webmachine のドキュメントによると、同じアプリケーションの 2 つのインスタンスを開始できるはずですが、erlang アプリで異なる構成を使用する必要があります。

この問題に関するヘルプ/ディスカッションに感謝します!

4

1 に答える 1

0

子プロセスの構成は次の形式にする必要があります。

{Name,
 {webmachine_mochiweb, start, [WebConfig]},
  permanent, 5000, worker, [mochiweb_socket_server]}

whereNameWebConfigは、webmachine インスタンスに対して一意である必要があります。WebConfigパーツにはnameとプロパティが含まれている必要がありdispatch_groupます。例えば:

WebConfig = [{name,instance1},
             {dispatch_group,instance1},
             {ip, Ip},
             {port, Port},
             {log_dir, "priv/log"},
             {dispatch, Dispatch}],

したがって、複数のインスタンスの場合、スーパーバイザーの仕様に次のようなものがあるかもしれません:

WebConfig1 = [{name,instance1},
              {dispatch_group,instance1},
              {ip, Ip},
              {port, Port},
              {log_dir, "priv/log"},
              {dispatch, Dispatch}],
WebConfig2 = [{name,instance2},
              {dispatch_group,instance2},
              {ip, Ip},
              {port, Port+1},
              {log_dir, "priv/log"},
              {dispatch, Dispatch}],
Web1 = {instance1,
        {webmachine_mochiweb, start, [WebConfig1]},
        permanent, 5000, worker, [mochiweb_socket_server]},
Web2 = {instance2,
        {webmachine_mochiweb, start, [WebConfig2]},
        permanent, 5000, worker, [mochiweb_socket_server]},
Processes = [Web1, Web2],
{ok, { {one_for_one, 10, 10}, Processes} }.

もう 1 つ: 質問に表示されている名前から判断するとapplication_sup、webmachine./scripts/new_webmachine.shを実行し、アプリケーション名を として指定した可能性がありますapplication。もしそうなら、これをしないでください。なぜなら、applicationは主要な Erlang OTP モジュールの名前であり、あなたのコードはそれと衝突し、あらゆる種類の問題を引き起こすからです。

于 2014-03-12T13:56:09.433 に答える