[Erlang crisis] (5.1.4) port, erlang5.1.4
Original article, reproduced please indicate the source: Server non amateur research http://blog.csdn.net/erlib Sunface contact mailbox: cto@188.com
Port
In a manner similar to processes, Ports shoshould 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 are similar to process behavior patterns. They are data types that contain connections and sockets: TCP sockets, UDP sockets, SCTP sockets, and file descriptors.
Worker has a common function (similar to the processes () of a process) to calculate the total number of ports: length (erlang: ports ()). However, the output of this function contains the sum of all port types, so you cannot know the specific number of ports of a specific type. You can use the port_type of recon to sort them by port type.
---------------------------------------------------------
1> recon:port_types().
[{"tcp_inet",21480},
{"efile",2},
{"udp_inet",2},
{"0/1",1},
{"2/2",1},
{"inet_gethost 4 ",1}]
--------------------------------------------------------
Please 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.
When 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.
When Again, tracking these can be useful to assess load or usage of a system, detect leaks, and so on.
The list above contains the port and quantity of each type. The port type name is a string customized by Erlang VM. All ports with XXX_inet are usually sockets, And the prefix XXX is the protocol used (TCP, UDP, SCTP ). The efile type is for files. "0/1" and "2/2" are file descriptors of standard I/O (stdin and stdout) and error handling (stderr. Most other port types are given a name when interacting with the driver (dirver), representing the corresponding port programs14 or port drivers15.
Tracking the number of ports throughout the process can greatly help diagnose load or process leakage.
[14] http://www.erlang.org/doc/tutorial/c_port.html
Http://www.erlang.org/doc/tutorial/c_portdriver.html [15]
[14] http://www.erlang.org/doc/tutorial/c_port.html
Http://www.erlang.org/doc/tutorial/c_portdriver.html [15]