[Erlang危機](5.1.4)連接埠port,erlang5.1.4
原創文章,轉載請註明出處:伺服器非業餘研究http://blog.csdn.net/erlib 作者Sunface聯絡郵箱:cto@188.com
Port
In a manner similar to processes, Ports should be considered. Ports are a datatype that encompasses all kinds of connections and sockets opened to the outside world: TCP sockets, UDP sockets, SCTP sockets, file descriptors, and so on.
There is a general function (again, similar to processes) to count them: length(erlang:ports()) . However, this function merges in all types of ports into a single entity. Instead, one can use recon to get them sorted by type:
連接埠(ports)和進程的行為模式是很相近的,是一種包含了串連和sockets的資料類型:TCP sockets,UDP sockets,SCTP sockets,檔案描述符等等。
有一個通用的函數(和進程的processes()類似)來計算連接埠總數量:length(erlang:ports())。但這個函數的輸出包含了所有的連接埠類型的總和,因此你無法獲知某個特定類型連接埠的具體數目,可以使用recon的port_type來根據連接埠類型排序他們。
---------------------------------------------------------
1> recon:port_types().
[{"tcp_inet",21480},
{"efile",2},
{"udp_inet",2},
{"0/1",1},
{"2/2",1},
{"inet_gethost 4 ",1}]
--------------------------------------------------------
This list contains the types and the count for each type of port. The type name is a string and is defined by the Erlang VM itself.
All the *_inet ports are usually sockets, where the prefix is the protocol used (TCP, UDP, SCTP). The efile type is for files, while "0/1" and "2/2" are file descriptors for standard I/O channels (stdin and stdout) and standard error channels (stderr), respectively. Most other types will be given names of the driver they’re talking to, and will be examples of port programs 14 or port drivers 15.
Again, tracking these can be useful to assess load or usage of a system, detect leaks, and so on.
上面這個列表包含了每種類型的連接埠和數量。連接埠類型名是Erlang VM自訂的字串。所有以XXX_inet的連接埠通常都是sockets,其中XXX首碼就是所使用的協議(TCP,UDP,SCTP)。efile類型是針對檔案的,"0/1" 和 "2/2" 就是標準I/O(stdin和stdout),和錯誤處理(stderr)的檔案描述符。大多數其它的port類型在與驅動(dirver)互動時會給定一個名字,代表了相應的port programs14或port drivers15。
全程跟蹤連接埠數會對診斷負載或進程泄漏有極大的協助。
[14] http://www.erlang.org/doc/tutorial/c_port.html
[15] http://www.erlang.org/doc/tutorial/c_portdriver.html
[14] http://www.erlang.org/doc/tutorial/c_port.html
[15] http://www.erlang.org/doc/tutorial/c_portdriver.html