[erlang-questions] process stats

Gustav Simonsson gustav.simonsson@REDACTED
Sun Nov 4 14:25:26 CET 2012


One way of finding out more exact CPU utilization and other stats for one
or more Erlang processes from the Linux point of view could be to bind them
to a specific Erlang scheduler [1] which requires you to first bind each
Erlang scheduler to a CPU thread [2] (logical processor) rather than have
the OS migrate them at its will between the available threads.

After this you can find the thread id of the Linux thread executing that
Erlang scheduler [3].

Then you can look at interesting statistics such as CPU utilization for the
thread corresponding to that Erlang scheduler using for example the %cpu
format specifier to ps. There is also a bunch of interesting things under
stat in proc for each tid such as page faults stats and time scheduled in
kernel mode [4] which could be useful.

Things to consider is that the Erlang scheduler could have executed other
Erlang processes than the ones specificity bound to it. Also, if you bound
several Erlang processes to a Erlang scheduler, the Linux thread stats
would be for all of them. Also, binding Erlang processes to a scheduler is
not generally recommended and you might only want todo something like this
in a testing environment for benchmarking.

[1] Use the {scheduler, N} option (undocumented) to
erlang:spawn_opt/2,3,4,5. The number of schedulers can be found with
erlang:system_info(schedulers)
, and the scheduler for the calling process with
erlang:system_info(scheduler_id).

[2] Look at the +sbt options at
http://www.erlang.org/doc/man/erl.html#emu_flags

[3] You can find out the tids with ps -Leo pid,tid,comm | grep beam.
Finding the exact thread might be tricky, but if you bind all the processes
doing heavy stuff to one thread, that one should stand out if you add other
stats like %cpu and %mem to the format specifiers. A more explicit way
would be to call pid_t tid = syscall(SYS_gettid) in a NIF from the bound
Erlang processes you want to look at.

[4] man 5 proc, look under the stat and statm sections, you can read it
directly at /proc/<tid>/stat or use ps to list them.

Cheers,
Gustav Simonsson



On Fri, Nov 2, 2012 at 4:39 AM, József Bérces <jozsef.berces@REDACTED>wrote:

> **
> Hi,
>
> I am writing an application that runs in the background crunching some
> data and writing result files to the disk. It has a web interface to
> configure what data and how to process. And I was thinking about that it
> would be good to be able to present some stats on the web interface about
> which Erlang processes how much CPU resources used during the last
> second/minute/day/week etc.
>
> Is there any way to get this kind of info somehow without wasting too much
> resources on the stat collection itself? I do not want it for all Erlang
> processes, only for a well defined subset of them.
>
> eprof/fprof seem to be too heavy: they would take too much system
> resources and they would produce too detailed data for me.
>
> erlang:system_profile seems to be promising (I have not started playing
> with it) but it has that note in the doc that it is experimental so I am a
> bit afraid of it.
>
> I was also thinking about tracing my processes with the flag 'running' so
> I would get 'in' and 'out' message tags in a profiling process. I am not
> sure how much resources this would take.
>
> Any suggestions are welcome!
>
> Thanks,
> Jozsef
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121104/db163a9e/attachment.htm>


More information about the erlang-questions mailing list