Isolating memory of threads in JRuby
We're currently running Resque using JRuby and having issues with memory leaks. One of the nice things about Resque and Ruby/REE was that it used fork semantics which isolated memory leaks to a per job basis rather than a per VM basis (fork for each job).
It doesn't look like there are options for forking the JVM that ma开发者_StackOverflow社区ke sense but wondering if there are things you can do with isolating memory to threads so upon a stop event in a thread all memory created by that thread is destroyed regardless of not there are still references to it.
Threads are certainly not processes. If you're using threads, you are sharing a common pool of memory with the rest of the process, and so there's not really any concept of "memory created by that thread." It is possible to implement a VM such that threads get their own memory space, but in JRuby's case it would defeat many of the benefits of having native threads in the first place.
My recommendation would be to work with the JRuby team (e.g. me) to figure out what's leaking, and we'll fix it. The MRI approach is an ugly band-aid that only makes people lazy about memory and resource management in code.
精彩评论