[erlang-questions] Is the performance cost of inet:i() big or small?

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Tue May 22 16:10:44 CEST 2012

On 5/13/12 12:32 PM, skyman wrote:
> Hi all,
> 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?
I learned a trick during the Erlang Factory 2012 by Patrik Nyblom: When 
in doubt, read the source code of the virtual machine.

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.

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.

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 

Jesper Louis Andersen
   Erlang Solutions Ltd., Copenhagen, DK

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120522/b81ceaaa/attachment.htm>

More information about the erlang-questions mailing list