2

When sending a message between two remote nodes.

Does erlang:send use a single port like the one for epmd?

Marfeyh
  • 66
  • 4

1 Answers1

5

erlang:send does not use a single port like the one for epmd. Erlang uses the EPMD port to find other nodes, so all servers must be able to speak to each other on this port. In an Erlang Cluster, all nodes are connected to all other nodes in a mesh. The Erlang epmd will use two ports, one for discovering other erlang nodes (default port 4369) and dynamic range for the actual communication.

All nodes in a cluster must use the same epmd port number for listening.

Also, note that Epmd keeps track of which Erlang node is using which ports on the local machine. If you want to restrict the range of ports that Erlang will use for inter-Erlang node communication to let's say 9100-9105, you can add the following lines to your app.config setting the kernel variables 'inet_dist_listen_min' and 'inet_dist_listen_max'.

Example:

{ kernel, [
              {inet_dist_listen_min, 9100},
              {inet_dist_listen_max, 9105}
             ]},

Or when starting the erlang node using kernel variables 'inet_dist_listen_min' and 'inet_dist_listen_max'.

Example:

erl -sname foo -kernel inet_dist_listen_min 9100 inet_dist_listen_max 9105

ensure that the range you set provides enough ports for all the nodes in the cluster.

byaruhaf
  • 4,128
  • 2
  • 32
  • 50
  • Would that `set_env` example work? I suspect that the port is chosen before you have a chance to change any environment variables. – legoscia Feb 09 '17 at 11:05
  • 1
    @legoscia modified the answer cause using set_env does set the kernel variables, but the node continues using the original port numbers. Very strange. – byaruhaf Feb 10 '17 at 05:56