tags:

views:

166

answers:

1

Is there an OS-agnostic Perl module that puts a hard limit on the amount of virtual memory a process can use; e.g. so that the process will be killed if it starts eating up too much memory?

I see Apache::SizeLimit, which is obviously Apache specific; and Process::MaxSize, which requires you to call a check function (and also has a hacky way of checking process size).

I've used ulimit in the past, but it requires you (AFAIK) to have an extra launching process, and it is OS-specific.

Thanks, Jon

+1  A: 

I don't think perl can have any awareness of whether its memory usage is real or virtual. However if you remove real vs. virtual from your requirement, you could place a limit simply on the memory being used.

Devel::Size and Cache::SizeAwareMemoryCache might get you a bit closer, or BSD::Resource's setrlimit.

Ether
What `ulimit` does in a shell is exactly what `setrlimit` does in your process, so as long as Windows is not a requirement, I would say that `BSD::Resource` is the best choice here.
ephemient
I don't see how Devel::Size is going to help at all. It might be able to tell you how much a variable is using if it is not tied, but it doesn't know about the rest of the memory. Cache::SizeAwareMemoryCache is similarly limited and not suitable.
brian d foy
I was thinking perhaps iterating through all "largish" variables and seeing how much space each was taking, but that totally ignores the size of the perl executable itself, which is not insignificant unless there is a huge amount of data being loaded. Now I'm wondering if there's some way to determine the resources used by the executable.. other than by shelling out and calling top or ps :)
Ether