Spawn an elixir process w/ heap memory limits

Is there a way to spawn an elixir process w/ heap memory limit, to say something like:

start this process, but if it ever hits > 1 MB heap, kill it

2 Likes

Really curious about this. @rvirding or @bjorng pardon the direct mention – do you know of such a possibility?

1 Like

sure:

Process.flag(:max_heap_size, heap_size()) :: heap_size()

See: Erlang -- erlang

9 Likes

Exactly what I needed. Thanks!

Awesome, thank you.

Beware that large binaries are stored off-heap, so this limit won’t apply to them. See Sand: an Elixir sandbox

5 Likes

A typical example of this is: downloading a large file with HTTPoison (without streaming), as I just “discovered”.

I am looking for ways to automatically detect those extra non-streaming downloads on a given codebase.

Process.info(self())[:total_heap_size] won’t report it at all.

Process.flag(:max_heap_size, 100_000) won’t kill the process with a 500MB file.

Interesting article on the topic!

2 Likes