`
litaocheng
  • 浏览: 339844 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

local pid and remote pid

阅读更多
pid 既可以代表本地的process,也可以代表其他节点即远程 process,因此pid ! Msg,既可以向本地节点又可以向其他节点发送消息。

如何来区分local pid和remote pid呢,让我们先看看pid具体包含哪些信息。
打印pid变量的时候,其为X.Y.Z格式的数据,其中X代表的便是本地节点或者其他node(其可以为一个索引,指向某个已知节点),Y为4字节 unsigned integer代表的是process id(序列号,max 32767),Z为4个字节,为Serial(当pid中Y到达32767时,Z则增加)。
具体的pid数据格式请参考:http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#8.8

在分布式开发中,如果节点之间交互,涉及到pid,那么erlang会自动为我们进行local pid到remote pid的转化。具体请参看下例:
为了方便我们的观察,研究,我对kernel中的rpc模块作了一点小改动,添加了一些调试信息:
rpc.erl:
handle_call/3函数 Line 99添加:

io:format("rpc handle_call:[M:~p F:~p A:~p] From:~p~n", [Mod, Fun, Args, To]),


handle_info/2函数 Line 148添加:

io:format("rpc reply To: ~p Msg:~p~n", [To, Reply]),


do_call/3函数 Line 232

io:format("rpc docall: Node:~p self:~p~n", [Node, self()]),


添加完这三条打印信息,随后编译rpc,将rpc.beam放置在kernerl/ebin目录下。(修改前,相信你会把rpc.erl和rpc.beam都备份一下的)。

随后我们启动两个erlang shell:
Node A: erl -sname a
Node B: erl -sname b


在Node b中,我们register一个名叫proc_on_b的process:
(b@desktop)4> register(proc_on_b, spawn(fun() -> receive Msg -> Msg end end)).


在Node a中:
(a@desktop)7> rpc:call('b@desktop', erlang, whereis, [proc_on_b]).


查看屏幕的输出:
Node a:
(a@desktop)7> rpc docall: Node:'b@desktop' self:<0.35.0>
<5094.53.0>


Node b:
(b@desktop)5> rpc handle_call:[M:erlang F:whereis A:[proc_on_b]] From:{<6253.35.0>, #Ref<6253.0.0.79>}
(b@desktop)5> rpc reply To: {<6253.35.0>,#Ref<6253.0.0.79>} Msg:<0.53.0>


仔细的查看屏幕输出,在a中,显示的rpc调用process的pid为<0.35.0>,而在b中rpc module收到的From的pid为<6253.35.0>,这里erlang已经把a中的local pid转化成为b所使用的remote pid。这样,b节点可以方便的发送信息。同样a中收到的pid信息为<5094.53.0>,也是对b所返回的信息 Msg:<0.53.0>进行了转化。

是不是所有Node之间交互的pid都会进行转化呢?
我们再做下一个试验:
我们写一个模块,让其通过c:pid/3生成一个pid,然后返回给某个节点,看这个节点是否将这个pid进行了转化。
在b的某个模块(pid_test)中添加下面的函数:
get_pid() ->
c:pid(0, 2222, 1).


随后a中调用:
(a@desktop)10> rpc:call('b@desktop', pid_test, get_pid, []).
rpc docall: Node:'b@desktop' self:<0.35.0>

<5094.2222.1>

同样,b中的pid:<0.2222.1> 贝进行了转化。

对于global module,如果我们中间传递了local pid,在另一方显示的是remote pid。
分享到:
评论
1 楼 GodwitNow 2009-04-15  
终于明白创建进程的时候返回的三个数字是什么意思了。
这是不是说,每个节点上可创建的进程最多是32757*32767个呢?:)

相关推荐

    Nginx 控制 启动 脚本

    # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop nginx ### END INIT ...

    丹佛斯变频器FC300英文设计指南.pdf

     3.2.8 Local (Hand On) and Remote (Auto On) Control 22  3.3 Reference Handling 23  3.3.1 Reference Limits 24  3.3.2 Scaling of Preset References and Bus References 25  3.3.3 Scaling of Analog and...

    Centos开机自启动redis.txt

    在现代软件架构中,Redis(Remote Dictionary Server)是一种广泛使用的开源键值存储系统,它支持多种数据结构如字符串、哈希表、列表等,并且可以作为数据库、缓存以及消息中间件来使用。为了确保Redis服务能够在...

    JVM性能调优监控工具jps、jstack、jmap、jhat、jstat使用详解.docx

    语法格式如下:jstack [option] pid 或 jstack [option] executable core 或 jstack [option] [server-id@]remote-hostname-or-ip。指令行参数选项解释如下: * -l long listings,会打印出额外的锁信息,在发生...

    CentOS7中将Mysql添加为系统服务 - shangyingbin - 博客园.pdf

    例如,如果你找到的PID文件路径是`/usr/local/mysql/data/XXX.pid`,那么在`mysql.service`文件中,你需要指定`PIDFile`字段为此路径。 ```ini [Unit] Description=Mysql After=syslog.target network.target ...

    利用nginx反向代理tomcat服务器(非常详细,又不懂的可以m我)

    我下载的niginx版本是nginx-... #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';

    nginx.conf.txt

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log ...

    Tomcat添加为系统服务.docx

    PIDFile=/usr/local/apache-tomcat-8.5.31/tomcat.pid ExecStart=/usr/local/apache-tomcat-8.5.31/bin/startup.sh ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=...

    centos7安装FastDFS_v5.08及配置

    proxy_set_header X-Real-IP $remote_addr; } ``` 重启Nginx以应用新的配置: ```bash sudo systemctl restart nginx ``` 至此,FastDFS v5.08已经在CentOS 7上成功安装并配置完成。你可以通过上传文件测试其...

    Linux服务器scp无密码传输文件操作说明

    scp local_file remote_username@remote_ip:remote_file ``` 例如,将本地文件`/home/uniplat/tmp/nginx.pid`传输至远程服务器`46.17.189.251`的`uniplat`用户的`/home/uniplat/test.1`路径: ```bash scp /home/...

    Nginx安装与使用.docx

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '; access_log logs/access.log main; sendfile on; keepalive_timeout 65; gzip on; client_header_buffer_size 1k; large_client_...

    nginx.conf

     log_format main '$remote_addr - $remote_user [$time_local] "$request" '  '$status $body_bytes_sent "$http_referer" '  '"$http_user_agent" "$http_x_forwarded_for"';  access_log /var/log/nginx/...

    docker配置nginx静态文件服务.docx

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access....

    ansible实现nginx源码的自动化安装

    PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID ...

    Nginx 1.11.8 安装与配置

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; ... ``` 在配置文件中,还需要设置...

    nginx的介绍和使用.docx

    * log_format main '$remote_addr - $remote_user [$time_local] ''"$request" $status $bytes_sent ''"$http_referer" "$http_user_agent" ''"$gzip_ratio"'; // 指定日志格式 * access_log logs/access.log main...

    redis集群部署

    Redis(Remote Dictionary Server)是一种开源的高性能键值存储系统,常被用于数据库、缓存和消息中间件等场景。由于单机Redis存在容量和性能上的限制,因此在高并发和大数据量的应用场景下,通常采用Redis集群来...

    adb命令大全.zip

    2. **文件传输**:`adb push &lt;local&gt; &lt;remote&gt;` 将本地文件或目录推送到设备,`adb pull &lt;remote&gt; &lt;local&gt;` 从设备拉取文件或目录。 3. **进程管理**:`adb shell ps` 列出设备上的所有进程,`adb shell kill &lt;pid&gt;`...

    Nginx安装配置

    log_format main '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; } ``` 此配置文件包含以下关键部分: ...

    centOS8安装nginx及nginx配置

    PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/...

Global site tag (gtag.js) - Google Analytics