hubertlepicki

hubertlepicki

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?

Showing Posts 24 to 15

garazdawi

garazdawi

Erlang Core Team

That is true. However, since you cannot loop without calling functions I’ve very rarely found that to be a limiting factor.

hubertlepicki

hubertlepicki OP

I tried recon_trace - but it seems to be able to trace function calls only, not giving me any insight into what happens within functions themselves?

garazdawi

garazdawi

Erlang Core Team

Why not use tracing for this? Seems like a perfect fit.

hubertlepicki

hubertlepicki OP

Yeah, so I was trying to figure out what the library I use is allocating. And I’m not super familiar with the library internals, would be just good to have a snapshot at some point and look at the terms it creates, run some function again and see what’s been allocated more etc., basically to find what causes the bloat.

I have ended up doint precisely that but on a fork of library basically printing out the terms to file with File.write! :erlang.term_to_binary(some_variable) and then analysing that to figure out which terms are being duplicated unnecessarily.

garazdawi

garazdawi

Erlang Core Team

no, not at the moment.

arnomi

arnomi

Is there a way to get the information of :erlang.system_info(:procs) for only a single process/port?

sasajuric

sasajuric

Author of Elixir In Action

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

garazdawi

Erlang Core Team

Maybe :erlang.system_info(:procs) is closer to what you are looking for? From it you can get the values that are currently live on the stack.

hubertlepicki

hubertlepicki OP

Right, but if a process is not a nice member of OTP family, as in it’s a Cowboy protocol handler (i.e. process in which Phoenix’s web requests are being handled), and memory is being allocated within the same process there is nothing that will give me insight to the allocated memory. That’s sad, I know Java has tools that can do precisely that, it’s a shame we don’t have the same :slight_smile:

sasajuric

sasajuric

Author of Elixir In Action

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.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews