<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 5/13/12 12:32 PM, skyman wrote:
<blockquote
cite="mid:116fc4e4.9d78.13745c1c016.Coremail.cloudzen@163.com"
type="cite">
<div
style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">
<div
style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Hi
all,
<div>inet:i() can print all socket info statistics, and it is
very useful for monitoring the network for the Erlang
node. Is the performance cost of inet:i() big or small? Can
I use it in the production system?<br>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
I learned a trick during the Erlang Factory 2012 by Patrik Nyblom:
When in doubt, read the source code of the virtual machine.
<br>
<br>
inet:i() makes a call to erlang:ports() and then afterwards does
some work to format the result of this nicely. The erlang:ports/0
call is a BIF, so you can go to the BIF-table and look up that its
name in the C source is ports_0. Going to this function and reading
about the blocking behaviour tells you that you can only have one
such snapshot call running at a time and it only blocks concurrency
on ports one port at a time (It has to, it bumps a snapshot counter
in the port struct). This would suggest that the performance cost is
such that it won't block the whole system when it is run (which is
good), but it does have a cost if you call all the time.
<br>
<br>
More interestingly, the call also allocates quite the amount of
data. So you may end up with a spike in memory usage when you make
the call and the result is then dependent on how many ports you
have.
<br>
<br>
My guess is that it won't be highly problematic to use in production
unless you put it into a tight loop. If you are in doubt, you should
measure.
<br>
<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Jesper Louis Andersen
Erlang Solutions Ltd., Copenhagen, DK</pre>
</body>
</html>