Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are your strategies to keep the memory usage low?

Ruby is truly memory-hungry - but also worth every single bit.

What do you do to keep the memory usage low? Do you avoid big strings and use smaller arrays/hashes instead or is it no problem to concern about for you and let the garbage collector do the job?

Edit: I found a nice article about this topic here - old but still interesting.

like image 987
unexist Avatar asked Sep 27 '08 21:09

unexist


People also ask

Is there a way to free up memory?

To stop high RAM usage, start small by quitting programs you aren't using, restarting your computer, uninstalling unneeded programs, and scanning for any malware that may be on your device. If this doesn't work, consider downloading a RAM cleaning software or even installing more RAM.


2 Answers

I've found Phusion's Ruby Enterprise Edition (a fork of mainline Ruby with much-improved garbage collection) to make a dramatic difference in memory usage... Plus, they've made it extraordinarily easy to install (and to remove, if you find the need).

You can find out more and download it on their website.

like image 166
Ben Scofield Avatar answered Sep 20 '22 05:09

Ben Scofield


I really don't think it matters all that much. Making your code less readable in order to improve memory consumption is something you should only ever do if you need it. And by need, I mean have a specific case for the performance profile and specific metrics that indicate that any change will address the issue.

If you have an application where memory is going to be the limiting factor, then Ruby may not be the best choice. That said, I have found that my Rails apps generally consume about 40-60mb of RAM per Mongrel instance. In the scheme of things, this isn't very much.

You might be able to run your application on the JVM with JRuby - the Ruby VM is currently not as advanced as the JVM for memory management and garbage collection. The 1.9 release is adding many improvements and there are alternative VM's under development as well.

like image 22
Toby Hede Avatar answered Sep 22 '22 05:09

Toby Hede