hubertlepicki
Profiling memory usage in given process
I’ve got some requests misbehaving, and processes handling them suddenly allocate a lot of memory, which can crash my Beam VM.
I can monitor and detect that, I can also enforce max memory usage by process, that’s not an issue.
I would like to, however, know what is eating up the memory. Ideally I’d be able to take a snapshot of memory used by current process, have it dumped to a file that contains Erlang terms, which later I could analyse and find out what’s on stack, what’s on heap etc.
Is there something out there I can use to achieve that?
Most Liked
sasajuric
The stack trace should help you narrow down the problematic code. We actually had a similar situation recently, and we ended up periodically logging the processes with unusually high mem usage, together with their stack traces. In this particular situation that info was enough to completely understand the root cause. I agree that it’s not quite what you’re looking for, but it can help you in understanding the problem.
It’s also worth keeping in mind that in a general case excessive mem usage can be caused by other things, such as messages accumulated in the process queue, or refc binaries, or ets tables, so finding the cause is not necessarily as straightforward as logging the current heap of the process, which is why I mentioned a couple of different things in my previous answer.
garazdawi
That is true. However, since you cannot loop without calling functions I’ve very rarely found that to be a limiting factor.
axelson
You can run observer locally and connect to a remote node to view its information. Here’s a blog post about it: http://jbavari.github.io/blog/2016/03/11/using-erlang-observer-on-a-remote-elixir-server/
sasajuric
AFAIK, it’s not possible to get what you’re looking for out of the box. To get some clues, you could use a combination of the following:
- memory usage of the process
- process stack trace
- message queue length
- total binary memory usage
- total ETS memory usage
In case you don’t know which process is the offender, you might also need to include :initial_call and :registered_name (both available via Process.info).
Coupled with the knowledge of the code, this should help you narrow down the problem.
hubertlepicki
I already solved the issue as in why and what is happening. It was this bug in absinthe we stumbled upon: https://github.com/absinthe-graphql/absinthe/issues/569
I’d like to know if there’s something that’ll help me out next time tracking down such and similar issues 







