erlang分布式网络节点中会经常用到域名解析服务,这一块是由外部程序inet_gethost来实现的,主要为了将这一耗时不确定的操作独立于主逻辑之外,以免影响主进程中process的调度。与inet_gethost同等待遇的还有memsup,cpu_sup和disksup,都是作为主进程的子进程独立执行。
inet_gethost的调度路径是这样的:
1.gen_tcp:connect
2.inet:gethostbyaddr
3.inet:gethostbyaddr_tm_native()
4.inet_gethost_native:gethostbyaddr()
5.inet_gethost_native:getit()
6.inet_gethost_native:ensure_started()
7.inet_gethost_native:start_raw()
8.inet_gethost_native:run_once()
9.inet_gethost_native:do_open_port()
10.inet_gethost_native:open_port({spawn, "inet_gethost 4 "}
11./usr/local/lib/erlang/erts-8.3/bin/inet_gethost
整个服务的启动,是由第一次gethostbyname()调用触发完成的,默认情况下会有4个inet_gethost进程为单一个节点服务,并且这4个inet_gethost进程被这一个节点独占,其他节点会有自己的独占inet_gethost服务。