Hacker News new | ask | show | jobs
by thinkbohemian 4228 days ago
> 2.0.0 means no memory errors

2.1 has a totally new GC setup (generational GC). It is guaranteed to use more memory (expect 3~5%), but be MUCH MUCH MUCH faster. Typically you can trade off running one less Puma worker to decrease memory usage, and the increase in speed may make up for it. Alternatively you can bump up to 2x dynos, and cut the number of dynos you have in half. If you haven't tried 2.1.3 or above do yourself a favor and revisit. The 2.1.3 patch means memory grows much more slowly.

Also if you didn't see my post on memory profiling: http://www.schneems.com/2014/11/07/i-ram-what-i-ram.html (It got over 40 upvotes on reddit, and like 3 on HN, again...HN what is going on? I've had much less substantial posts make it front page). That post shows you how to remove ~30% starting RAM (by bumping mail version to 2.6.3+) and shows you can profile and remove libraries that are using a ton of memory in your app.

You can also use something like puma_worker_killer (or unicorn_worker_killer) to tame your memory growth if it only balloons over 512mb after a while, but ultimately those two solutions are bandaids.

Ruby 2.0 isn't going to be supported forever and the generational GC is definitely here to stay. Maybe try the 2.2.0 preview (it's on Heroku), it has 3 generations (total) which means much less retained memory and you still get speed performance improvements.

I see most of the bigger production apps using 2.1+ fwiw.

1 comments

I agree with everything you said, but until Heroku offers larger dynos by default it's better to use 2.0.0 -if- you typically only use a dyno or two.