erlangian-distributiono2o是什么意思思

Erlang -- Distributed Erlang
13 Distributed Erlang
A distributed Erlang system consists of a number of
Erlang runtime systems communicating with each other. Each such
runtime system is called a node. Message passing between
processes at different nodes, as well as links and monitors, are
transparent when pids are used. Registered names, however, are
local to each node. This means that the node must be specified as well
when sending messages, and so on, using registered names.
The distribution mechanism is implemented using TCP/IP sockets.
How to implement an alternative carrier is described in the
A node is an executing Erlang runtime system that has
been given a name, using the command-line flag -name
(long names) or -sname (short names).
The format of the node name is an atom name@host.
name is the name given by the user. host is
the full host name if long names are used, or the first part of
the host name if short names are used. node() returns
the name of the node.
% erl -name dilbert
(dilbert@uab.ericsson.se)1& node().
'dilbert@uab.ericsson.se'
% erl -sname dilbert
(dilbert@uab)1& node().
dilbert@uab
A node with a long node name cannot communicate with a node
with a short node name.
The nodes in a distributed Erlang system are loosely connected.
The first time the name of another node is used, for example, if
spawn(Node,M,F,A) or net_adm:ping(Node) is called,
a connection attempt to that node is made.
Connections are by default transitive. If a node A connects to
node B, and node B has a connection to node C, then node A
also tries to connect to node C. This feature can be turned off by
using the command-line flag -connect_all false, see the
manual page in ERTS.
If a node goes down, all connections to that node are removed.
Calling erlang:disconnect_node(Node) forces disconnection
of a node.
The list of (visible) nodes currently connected to is returned by
The Erlang Port Mapper Daemon epmd is automatically
started at every host where an Erlang node is started. It is
responsible for mapping the symbolic node names to machine
addresses. See the
manual page in ERTS.
In a distributed Erlang system, it is sometimes useful to
connect to a node without also connecting to all other nodes.
An example is some kind of O&M functionality used to
inspect the status of a system, without disturbing it. For this
purpose, a hidden node can be used.
A hidden node is a node started with the command-line flag
-hidden. Connections between hidden nodes and other nodes
are not transitive, they must be set up explicitly. Also, hidden
nodes does not show up in the list of nodes returned by
nodes(). Instead, nodes(hidden) or
nodes(connected) must be used. This means, for example,
that the hidden node is not added to the set of nodes that
global is keeping track of.
This feature was added in Erlang 5.0/OTP R7.
A C node is a C program written to act as a hidden node
in a distributed Erlang system. The library Erl_Interface
contains functions for this purpose. For more information about
C nodes, see the
application and
Authentication determines which nodes are allowed to communicate
with each other. In a network of different Erlang nodes, it is
built into the system at the lowest possible level. Each node has
its own magic cookie, which is an Erlang atom.
When a node tries to connect to another node, the magic cookies
are compared. If they do not match, the connected node rejects
the connection.
At start-up, a node has a random atom assigned as its magic
cookie and the cookie of other nodes is assumed to be
nocookie. The first action of the Erlang network
authentication server (auth) is then to read a file named
$HOME/.erlang.cookie. If the file does not exist, it is
created. The UNIX permissions mode of the file is set to octal
400 (read-only by user) and its contents are a random string. An
atom Cookie is created from the contents of the file and
the cookie of the local node is set to this using
erlang:set_cookie(node(), Cookie). This also makes
the local node assume that all other nodes have the same cookie
Thus, groups of users with identical cookie files get Erlang
nodes that can communicate freely and without interference from
the magic cookie system. Users who want to run nodes on separate
file systems must make certain that their cookie files are
identical on the different file systems.
For a node Node1 with magic cookie Cookie to be
able to connect to, or accept a connection from, another node
Node2 with a different cookie DiffCookie,
the function erlang:set_cookie(Node2, DiffCookie) must
first be called at Node1. Distributed systems with
multiple user IDs can be handled in this way.
The default when a connection is established between two nodes,
is to immediately connect all other visible nodes as well. This
way, there is always a fully connected network. If there are
nodes with different cookies, this method can be inappropriate
and the command-line flag -connect_all false must be set,
manual page in ERTS.
The magic cookie of the local node is retrieved by calling
erlang:get_cookie().
Some useful BIFs for distributed programming
(for more information, see the
manual page in ERTS:
Description
erlang:disconnect_node(Node)
Forces the disconnection of a node.
erlang:get_cookie()
Returns the magic cookie of the current node.
is_alive()
Returns true if the runtime system is a node and can connect to other nodes, false otherwise.
monitor_node(Node, true|false)
Monitors the status of
Node. A message{nodedown, Node} is received
if the connection to it is lost.
Returns the name of the current node. Allowed in guards.
Returns the node where Arg, a pid, reference, or port, is located.
Returns a list of all visible nodes this node is connected to.
nodes(Arg)
Depending on Arg,
this function can return a list not only of visible nodes,
but also hidden nodes and previously known nodes, and so on.
erlang:set_cookie(Node, Cookie)
Sets the magic cookie used
when connecting to Node. If Node is the
current node, Cookie is used when connecting to
all new nodes.
spawn[_link|_opt](Node, Fun)
Creates a process at a remote node.
spawn[_link|opt](Node, Module, FunctionName, Args)
Creates a process at a remote node.
Distribution BIFs
Examples of command-line flags used for distributed programming
(for more information, see the
manual page in ERTS:
Command-Line Flag
Description
-connect_all false
Only explicit connection
set-ups are used.
Makes a node into a hidden node.
-name Name
Makes a runtime system into a node, using long node names.
-setcookie Cookie
Same as calling erlang:set_cookie(node(), Cookie).
-sname Name
Makes a runtime system into a node, using short node names.
Distribution Command-Line Flags
Examples of modules useful for distributed programming:
In the Kernel application:
Description
A global name registration facility.
global_group
Grouping nodes to global name registration groups.
Various Erlang net administration routines.
net_kernel
Erlang networking kernel.
Kernel Modules Useful For Distribution.
In the STDLIB application:
Description
Start and control of slave nodes.
STDLIB Modules Useful For Distribution.Erlang -- Using SSL for Erlang Distribution
4 Using SSL for Erlang Distribution
This section describes how the Erlang distribution can use
SSL to get extra verification and security.
The Erlang distribution can in theory use almost any
connection-based protocol as bearer. However, a module that
implements the protocol-specific parts of the connection setup is
needed. The default distribution module is inet_tcp_dist
in the Kernel application. When starting an
Erlang node distributed, net_kernel uses this module to
set up listen ports and connections.
In the SSL application, an exra distribution
module, inet_tls_dist, can be used as an
alternative. All distribution connections will use SSL and
all participating Erlang nodes in a distributed system must use
this distribution module.
The security level depends on the parameters provided to the
SSL connection setup. Erlang node cookies are however always
used, as they can be used to differentiate between two different
Erlang networks.
To set up Erlang distribution over SSL:
Step 1: Build boot scripts including the
SSL application.
Step 2: Specify the distribution module for
net_kernel.
Step 3: Specify the security options and other
SSL options.
Step 4: Set up the environment to always use SSL.
The following sections describe these steps.
Boot scripts are built using the systools utility in the
sasl application. For more information on systools,
see the sasl documentation. This is only an example of
what can be done.
The simplest boot script possible includes only the Kernel
and STDLIB applications. Such a script is located in the
bin directory of the Erlang distribution. The source for the
script is found under the Erlang installation top directory under
releases/&OTP version&/start_clean.rel.
Do the following:
Copy that script to another location (and preferably another
Add the applications Crypto, Public Key, and
SSL with their current version numbers after the
STDLIB application.
The following shows an example .rel file with SSL
{release, {"OTP
APN 181 01","R15A"}, {erts, "5.9"},
[{kernel,"2.15"},
{stdlib,"1.18"},
{crypto, "2.0.3"},
{public_key, "0.12"},
{ssl, "5.0"}
The version numbers differ in your system. Whenever one of the
applications included in the script is upgraded, change the script.
Do the following:
Build the boot script.
Assuming the .rel file is stored in a file
start_ssl.rel in the current directory, a boot script
can be built as follows:
1& systools:make_script("start_ssl",[]).
There is now a start_ssl.boot file in the current
directory.
Do the following:
Test the boot script. To do this, start Erlang with the
-boot command-line parameter specifying this boot script
(with its full path, but without the .boot suffix). In
UNIX it can look as follows:
$ erl -boot /home/me/ssl/start_ssl
Erlang (BEAM) emulator version 5.0
Eshell V5.0
(abort with ^G)
1& whereis(ssl_manager).
The whereis function-call verifies that the SSL
application is started.
As an alternative to building a bootscript, you can explicitly
add the path to the SSL ebin directory on the command
line. This is done with command-line option -pa. This
works as the SSL application does not need to be started for the
distribution to come up, as a clone of the SSL application is
hooked into the Kernel application. So, as long as the
SSL application code can be reached, the distribution starts.
The -pa method is only recommended for testing purposes.
The clone of the SSL application must
enable the use of the SSL code in such an early bootstage as
needed to set up the distribution. However, this makes it
impossible to soft upgrade the SSL application.
The distribution module for SSL is named inet_tls_dist
and is specified on the command line with option -proto_dist.
The argument to -proto_dist is to be the module
name without suffix _dist. So, this distribution
module is specified with -proto_dist inet_tls on the
command line.
Extending the command line gives the following:
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_tls
For the distribution to be started, give the emulator a name as well:
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_tls -sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0
(abort with ^G)
(ssl_test@myhost)1&
However, a node started in this way refuses to talk
to other nodes, as no SSL parameters are supplied
(see the next section).
For SSL to work, at least
a public key and a certificate must be specified for the server
side. In the following example, the PEM-files consist of two
entries, the server certificate and its private key.
On the erl command line you can specify options that the
SSL distribution adds when creating a socket.
The simplest SSL options in the following list can be specified
by adding the
prefix server_ or client_ to the option name:
cacertfile
reuse_sessions
secure_renegotiate
hibernate_after
ciphers (use old string format)
The server can also take the options dhfile and
fail_if_no_peer_cert (also prefixed).
client_-prefixed options are used when the distribution
initiates a connection to another node. server_-prefixed
options are used when accepting a connection from a remote node.
More complex options, such as verify_fun, are currently not
available, but a mechanism to handle such options may be added in
a future release.
Raw socket options, such as packet and size must not
be specified on the command line.
The command-line argument for specifying the SSL options is named
-ssl_dist_opt and is to be followed by pairs of
SSL options and their values. Argument -ssl_dist_opt can
be repeated any number of times.
An example command line can now look as follows
(line breaks in the command are for readability,
and are not be there when typed):
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_tls
-ssl_dist_opt server_certfile "/home/me/ssl/erlserver.pem"
-ssl_dist_opt server_secure_renegotiate true client_secure_renegotiate true
-sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0
(abort with ^G)
(ssl_test@myhost)1&
A node started in this way is fully functional, using SSL
as the distribution protocol.
A convenient way to specify arguments to Erlang is to use environment
variable ERL_FLAGS. All the flags needed to
use the SSL distribution can be specified in that variable and are
then interpreted as command-line arguments for all
subsequent invocations of Erlang.
In a Unix (Bourne) shell, it can look as follows (line breaks are for
readability, they are not to be there when typed):
$ ERL_FLAGS="-boot /home/me/ssl/start_ssl -proto_dist inet_tls
-ssl_dist_opt server_certfile /home/me/ssl/erlserver.pem
-ssl_dist_opt server_secure_renegotiate true client_secure_renegotiate true"
$ export ERL_FLAGS
$ erl -sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0
(abort with ^G)
(ssl_test@myhost)1& init:get_arguments().
[{root,["/usr/local/erlang"]},
{progname,["erl "]},
{sname,["ssl_test"]},
{boot,["/home/me/ssl/start_ssl"]},
{proto_dist,["inet_tls"]},
{ssl_dist_opt,["server_certfile","/home/me/ssl/erlserver.pem"]},
{ssl_dist_opt,["server_secure_renegotiate","true",
"client_secure_renegotiate","true"]
{home,["/home/me"]}]
The init:get_arguments() call verifies that the correct
arguments are supplied to the emulator.Erlang distribution Erlangian distribution的用法和样例:
When told the data are from an exponential or Erlang distribution the Six Sigma Black Belt should know that the run chart is preferred over the standard X control chart.
当被告知数据来自于指数函数或服从厄兰分布,6西格玛黑带应了解这时候趋势图优于标准的X控制图。
Furthermore, the new property of conditional Erlang distribution is proved, by which the distribution of stationary waiting time is obtained.
此外,发现并证明了条件Erlang分布的若干新性质,根据这些性质对等待时间进行分析,得到了稳态下等待时间的分布;
The result shows that their relative errors are within 5%,the daily-arriving-ship quantity is close to Normal distribution,the headway is close to Erlang distribution in inland waterway. 9 tabs,4 figs,9 refs.
比较结果表明其相对误差均在5%25以内,说明内河航道日到船艘数服从正态分布,日船头间距近似为爱尔朗分布。
In terms of daily arrival data, statistic and analyze ship flows laws. among which, daily arriving ship according with Normal Distribution, the average headway according with Erlang Distribution approximately.
根据到船资料,统计分析了船舶流到船规律,其中日到船近似服从正态分布,日到船平均船头间距近似服从爱而朗分布,为航道通过能力的计算提供理论基础。
By statistical analysis,their distribution charac- ters are deduced that the non-production waiting time follows the Erlang distribution,while the fuel price fol- lows Weibull distribution.
通过统计数据,指出它们的分布特点,并通过假设检验,得到非生产停泊时间符合爱尔朗分布,燃油价格符合威布尔分布的结论。
Erlang distribution Erlangian distribution的海词问答与网友补充:
Erlang distribution Erlangian distribution的相关资料:
相关词典网站:什么是Gamma distribution,什么是Erlang分布_百度作业帮
什么是Gamma distribution,什么是Erlang分布
什么是Gamma distribution,什么是Erlang分布
就是伽马分布和爱尔兰分布下面给个参考解释(应用)链接:/question/.html/myweb/baike/WordViewHistory.aspx?id=312500您所在的位置: &
浅析Erlang分布的核心技术
浅析Erlang分布的核心技术
javaeye论坛
本文简单介绍了Erlang系统的核心技术和几个重要特性:分布、多核心支持、fp;并对erlang最强大的特性――分布特性做了重点介绍。
Erlang系统在我看来有3个特性: 1. 分布 2. 多核心支持 3. fp。 这3个特性中分布我认为是erlang最强大的,从第一个版本就支持到现在,相对非常成熟,而多核心支持是这几年才加进去的。 erlang的分布系统做到了2点:
1.节点的位置无关性;
2. 对用户分布式透明的。
具体体现就是node是靠名字识别的, 进程也是靠pid来识别。 分布系统就要实现节点间通讯,erlang也不列外。 erlang的节点通讯介质是可以替换的 目前官方版本支持tcp, ssl通讯。 可以用 -proto_dist xxxx来选择通道。 目前支持inet_ssl inet_tcp 用户很容易模仿这这2个通讯协议,写个自己的传输通道,就是要求这个通道是可靠的,不能丢失信息。 这几个实现防火墙友好:
{inet_dist_use_interface, ip_address()}
//If the host of an Erlang node has several network interfaces, //this parameter specifies which one to listen on. See inet(3) for the type definition of ip_address().
{inet_dist_listen_min, First}
See below.
{inet_dist_listen_max, Last}
Define the First..Last port range for the listener socket of a distributed Erlang node.
erlang的内核里面和分布相关的erl模块主要有net_kernel inet_tcp_dist inet_ssl_dist inet_tcp dist_util erlang(trap send/link等语义)。 当用户运行erl -sname xxxxx启动erlang系统的时候 kernel模块就会启动net_kernel和epmd模块。 epmd的作用是提供一个node名称到监听地址端口的映射。epmd值守在知名端口4369上. net_kernel会启动proto_dist比如说inet_tcp_dist监听端口,同时把端口报到epmd.
这时候erts就准备好了节点通讯。 这时候另外一个节点要和我们通讯的时候,首先要连接,流程大概是这样的: 1. 根据节点名找到节点地址。 2. 查询节点的4369端口,也就是epmd,向它要节点对应的inet_tcp_dist监听的端口。 3. 发起连接, 握手,cookie认证,如果未授权就失败。 4. 记录节点名称和响应的信息。 所以节点要正常通讯要考虑到firewall和nat的影响,以及cookie正常。
要给节点发消息首先要保证我们和节点联系过,也就是说我们的节点表里可以查到这个节点。 net_kernel要节点的可用性, 会定期发tick消息坚持节点的可达。对端节点也会主动发送nodeup,nodeup等消息,协助维护。
net_ticktime = TickTime
Specifies the net_kernel tick time. TickTime is given in seconds. Once every TickTime/4 second,all connected nodes are ticked (if anything else has been written to a node) and if nothing has been received from another node within the last four (4) tick times that node is considered to be down. This ensures that nodes which arenot responding, for reasons such as hardware errors, are considered to be down.
节点有2种类型可见的和不可见的。erlang节点是可见的, c_interface写的节点不可见,因为c模块提供的节点能力有限。 erlang进程见通讯可以通过 1. pid& 2.进程名称 来进行。 erlang系统很大的威力就在用elang实现了名称和pid的全局性维护。也就是说erlang做了个相当复杂的模块来解决名称失效 重复 查询功能。正常情况下名称是全局性的,也就是erlang的节点是全联通的,可以通过来调整。
auto_connect = Value
Specifies when no will be automatically connected. If this parameter is not specified, a node is always automatically connected, e.g when a message is to be sent to that node. Value is one of:
Connections are never automatically connected, they must be explicitly connected. See net_kernel(3).
Connections will be established automatically, but only once per node. If a node goes down, it must thereafter be explicitly connected. See net_kernel(3).
erlang实现透明进程通信的关键点在于pid的变换: pid {X,Y,Z} 在发到网络的时候发出去的格式是{sysname, Y, Z} 因为节点之前互相联系过 所以互相知道对方的sysname, 而且sysname在dist_entry里保存,当对端收到dec_pid的时候,用peer sysname 的查到在自己dist_entry里面的索引,然后用这个index 来构造新的pid,即 {index, Y, Z}。 erlang给一个pid发消息的时候, 首先检查Pid是本地的还是外部的, 如果是外部的,则进行上面的变换,然后通过inet_tcp_dist模块,沿着inet_tcp, inet_drv这条线发送出去。 这条消息到达对端的时候 inet_drv首先受到这条消息, 照理说应该提交给inet_tcp, 然后再到inet_tcp_dist, net_kernel来处理.但是erlang为了效率的考虑做了个折中。在inet_drv里面driver_output*中检查消息的类型 如果是dist来的消息,就给erts_net_message来处理。 这个erts_net_message处理以下几个重要消息:
#define DOP_SEND 2
#define DOP_EXIT 3
#define DOP_UNLINK 4
#define DOP_NODE_LINK 5
#define DOP_REG_SEND 6
#define DOP_GROUP_LEADER 7
#define DOP_EXIT2 8
#define DOP_SEND_TT 12
#define DOP_EXIT_TT 13
#define DOP_REG_SEND_TT 16
#define DOP_EXIT2_TT 18
#define DOP_MONITOR_P 19
#define DOP_DEMONITOR_P 20
#define DOP_MONITOR_P_EXIT 21
如果是DOP_SEND的话,就把message放到变换好的进程的队列中去。 这个核心的功能,由beam的c模块(dist.c, erl_node_tables.c, io.c )和net_kernel模块一起实现。然后在这底层的原语上进一步实现了如rpc 这样的上层模块,进一步方便了用户.
【编辑推荐】
【责任编辑: TEL:(010)】
关于&&&&&&的更多文章
随着信息系统的快速发展,海量的信息需要可靠存储的同时,还能被
诞生于1991年的Java如今已经成为世界范围内应用最为广泛的编程语言之一,专题中...
这周的头版头条是“双十一”。凌晨12点守在电脑前抢东
Angular.js 是一个MV*(Model-View-Whatever,不管是M
本周,搜狗浏览器被爆存在重大漏洞的消息被炒得沸沸扬
本书是目前所能找到的最实用、最全面的Linux指南和参考手册,也是唯一一本提供以下全部内容的书籍:
更好更实用的示例覆盖了实
51CTO旗下网站

我要回帖

更多关于 o2o是什么意思 的文章

 

随机推荐