Erlang/OTP's global module

Source: Internet
Author: User
Reprinted: http://blog.csdn.net/cuiweican/archive/2010/07/14/5735476.aspx

The Erlang/OTP's global module can be used to name the processes in the Erlang distributed system in the form of atoms to ensure that each process in the distributed system has a unique name at the same time.

Now let's take a look at the performance of the global module in actual operations. register the same name in two Erlang nodes that are not connected at the beginning, and then connect the two nodes, the system will monitor the two nodes with the same name, and will cancel the name registration in one node.

First, register name a on two independent nodes (these two nodes are started with Erl-sname one and Erl-sname two respectively) and perform the following operations on one node,

Eshell v5.6.2 (abort with ^ g)
(One @ cuiweican) 1> Global: register_name (A, self ()).
Yes
(One @ cuiweican) 2> Global: whereis_name ().

From the above we can see that the name registration is successful (register_name returns yes). When whereis_name is used for query, as we expected, this function returns the value of self, that is, the PID of the Process shell.

Now the same operation is performed on the two node.

Eshell v5.6.2 (abort with ^ g)
(Two @ cuiweican) 1> Global: register_name (A, self ()).
Yes
(Two @ cuiweican) 2> Global: whereis_name ().

Similarly, the name is successfully registered. Note that both nodes have successfully registered the global name A, because there is no connection between the two nodes. Once these two nodes are connected, Erlang/OTP will automatically resolve this conflict. By default, one of them will be deregistered.

Now let's take a look at what will happen when two nodes are connected. We ping the node one to two to connect the two nodes.

(One @ cuiweican) 3> net_adm: Ping (two @ cuiweican ).
Pong
(One @ cuiweican) 4>
= Info report ==== 13-feb-2009: 03: 05: 22 ====
Global: Name Conflict terminating {,}

(One @ cuiweican) 4> Global: whereis_name ().

(One @ cuiweican) 5>

According to the report output from one node, the node two name is canceled. When node Two Queries name a, it will find that name a is registered in node one.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.