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

25 views
Skip to first unread message

skyman

unread,
May 13, 2012, 6:32:34 AM5/13/12
to erlang-q...@erlang.org
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?

Thanks in advance!




Jesper Louis Andersen

unread,
May 22, 2012, 10:10:44 AM5/22/12
to skyman, erlang-q...@erlang.org
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 measure.



-- 
Jesper Louis Andersen
  Erlang Solutions Ltd., Copenhagen, DK
Reply all
Reply to author
Forward
0 new messages