Erlang: How to limit the memory assigned to a process
Asked Answered
Y

2

5

What I'm asking is if it's possible to limit memory (heap or stack) assigned to a specific process, so that this process can't exceed it. Maybe something like "process_flag(min_heap_size, MinHeapSize)", but for the maximum heap.

Yacht answered 4/12, 2012 at 9:21 Comment(1)
I don't think it is possible now.Bellyache
F
6

You could put together some kind of process tracking gen_server that periodically checks assigned processes for memory footprint and kills them if it exceeds a certain amount.

Using a combination of process_info(Pid, memory). and exit(Pid, Reason) calls, this should be quite manageable.

Fireboat answered 4/12, 2012 at 14:14 Comment(1)
That's what I did :-) I made a check every 2 seconds, but in 2 seconds everything can happen!Yacht
H
3

You could use spawn_opt with max_heap_size

Haeckel answered 6/12, 2016 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.