Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much memory should Rails and Unicorn consume?

I just deployed a Rails 4 application on Unicorn.

It has no traffic, and it seems to me that it is eating a lot of memory.

Just running idle with 2 unicorn workers its using 253 MB of ram. Is this to be expected?

I use some gems that might be memory hungry, gemfile

gem 'rack-ssl'
gem 'jquery-rails'
gem 'activeadmin'      
gem 'american_date'
gem 'paperclip'
gem 'cancan'
gem 'pdfkit'
gem 'newrelic_rpm'
gem 'select2-rails'
gem 'whenever', :require => false
gem 'paymill'
gem 'pg'
gem 'queue_classic'
gem 'rails-observers'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'
gem 'sass-rails', :github => 'rails/sass-rails'
gem 'coffee-rails', :github => "rails/coffee-rails"
gem 'uglifier', '>= 1.3.0'
gem 'jquery-ui-rails'
gem 'foreman'
gem 'jquery-turbolinks'
gem 'turbolinks'
gem 'unicorn'
gem 'capistrano'
gem 'rvm-capistrano'

For the htop

  CPU[|                                                   0.7%]     Tasks: 38, 10 thr; 1 running
  Mem[|||||||||||||||||||||||||                      253/995MB]     Load average: 0.27 0.17 0.14 
  Swp[                                                   0/0MB]     Uptime: 11:00:36

 PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
  844 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:04.00 unicorn worker[1] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  803 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:00.00 unicorn worker[1] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  800 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:04.33 unicorn worker[1] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  837 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:03.48 unicorn worker[0] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  802 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:00.03 unicorn worker[0] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  798 deployer   20   0  467M  109M  2560 S  0.0 11.0  0:03.85 unicorn worker[0] -D -c /home/deployer/apps/application/shared/config/unicorn.rb -E production
  801 deployer   20   0  270M  107M  5992 S  0.0 10.8  0:00.00 unicorn master -D -c /home/deployer/apps/application/shared/config/unic

The unicorn workers show up three times each. Is this correct?

from monit log

System   Status Load    CPU Memory                  Swap
server   Running    [0.02] [0.09]   25.4% [259492 kB]   0.0% [0 kB]
Process         Status  Uptime  CPU Total   Memory Total
unicorn         Running 10h 48m     0.0%    32.8% [334828 kB]
unicorn_worker_0    Running 10h 47m     0.0%    11.0% [112252 kB]
unicorn_worker_1    Running 10h 47m     0.0%    11.0% [112300 kB]
postgresql          Running 10h 48m     0.0%    1.7%  [18100 kB]
nginx           Running 10h 48m     0.0%    0.8%  [8592 kB]

Do you need more information to tell me if this is a high memory consumption?

like image 752
Andreas Lyngstad Avatar asked Sep 23 '13 08:09

Andreas Lyngstad


1 Answers

It's perfectly normal, each unicorn worker is a separated process.

You see three processes because you ask for two workers. So you have the master process which spawn workers and respond to user signals, and the two other are actual worker processes.

Having such isolated processes consumes more memory but is in fact very cool : it's what allow to do graceful restart, having some workers that shut down immediately and others kept alive until their done processing their requests.

Please also note that when you do a graceful restart (USR2 signal), your usual memory consumption will be, for a short time, doubled. That's because a new master is started to accept new requests, spawn its own workers, and previous master won't shut down until all its workers finished processing requests.

Edit : to answer about the quantity of ram used by each process, that's fine too. My work app consumes around 315MO per process. A pre-release side project with about as much gem as yours is around 280MO per process.

like image 56
kik Avatar answered Sep 19 '22 02:09

kik