Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do Heroku dynos use swap memory?

I'm hosting my Rails 4.1.4 project with 2 Unicorn processes on free dyno for my development server. After the app running for a while, sometimes I feel getting slow. I added New relic, logentries, and enable log-runtime-metrics. Then I look at New relic and logentries

enter image description here

» heroku web.1  - - source=web.1 dyno=heroku.21274089.82eb32b4-c547-4041-b452-d3fedae05ee9 sample#load_avg_1m=0.00 sample#load_avg_5m=0.00 sample#load_avg_15m=0.01
» heroku web.1  - - source=web.1 dyno=heroku.21274089.82eb32b4-c547-4041-b452-d3fedae05ee9 sample#memory_total=393.41MB sample#memory_rss=368.38MB sample#memory_cache=4.47MB sample#memory_swap=20.56MB sample#memory_pgpgin=121244pages sample#memory_pgpgout=25796pages

What I don't understand is my dyno’s memory is only sample#memory_rss=368.38MB, but why it already uses swap memory sample#memory_swap=20.56MB? Because from what I thought from heroku article https://devcenter.heroku.com/articles/dynos#memory-behavior, it should switch to swap memory if it reaches dyno's memory which is 512 Mb for free dyno.

like image 549
Samnang Avatar asked Aug 17 '14 10:08

Samnang


People also ask

How does dyno work in Heroku?

As explained in Heroku's docs, Dynos are simply lightweight Linux containers dedicated to running your application processes. At the most basic level, a newly deployed app to Heroku will be supported by one Dyno for running web processes.

How do I reduce heroku memory usage?

Use jemalloc to reduce Rails memory usage On Heroku, you can add jemalloc using a buildpack. For my app, it resulted in ~20% memory usage decrease. Just make sure to test your app with jemalloc thoroughly on a staging environment before deploying it to production.

Is one dyno enough for Heroku?

Heroku provides enough free hours to run a single dyno continuously for a month, but if we need a worker dyno for background processing (most apps do), we will not have enough free dyno hours. Free dynos are for great for demos, experimentation, and perhaps a staging app. For production apps, we need to pay.

How does Heroku automatically restart dynos?

Automatic dyno restartscreate a new release by deploying new code. change your config vars. change your add-ons. run heroku restart.


1 Answers

I was seeing significant swap even when using only 50% of available RAM in my app, so I asked. Here's a quote from their support team:

We leave Ubuntu's swappiness at its default of 60 on our runtimes, including PX dynos.

A value of 60 ensures that your app will begin swapping well before it reaches max memory. The Linux kernel parameter vm.swappiness ranges from 0 to 100, with 0 indicating no swap and 100 indicating always swap.

So when running on Heroku you should expect your application to swap even if the footprint of your app is far smaller than the advertised RAM of your dyno.

like image 131
Brian P O'Rourke Avatar answered Oct 24 '22 21:10

Brian P O'Rourke