Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicorn cannot allocate memory

i need your help!

I have deployed my Rails app in Ubuntu 12.04, using Nginx, MySQL, Solr and Unicorn.

Every mentioned service is started, instead of unicorn, which says following:

I, [2013-02-11T16:10:20.187989 #27547] INFO -- : Refreshing Gem list I, [2013-02-11T16:10:52.159198 #27547] INFO -- : unlinking existing socket=/var/www/staging/shared/unicorn.sock I, [2013-02-11T16:10:52.159488 #27547] INFO -- : listening on addr=/var/www/staging/shared/unicorn.sock fd=12 E, [2013-02-11T16:10:52.161513 #27547] ERROR -- : Cannot allocate memory - fork(2) (Errno::ENOMEM) /var/www/staging/shared/gems/ruby/1.9.1/gems/unicorn-4.5.0/lib/unicorn/http_server.rb:496:in fork' /var/www/staging/shared/gems/ruby/1.9.1/gems/unicorn-4.5.0/lib/unicorn/http_server.rb:496:in spawn_missing_workers' /var/www/staging/shared/gems/ruby/1.9.1/gems/unicorn-4.5.0/lib/unicorn/http_server.rb:142:in start' /var/www/staging/shared/gems/ruby/1.9.1/gems/unicorn-4.5.0/bin/unicorn_rails:209:in ' /var/www/staging/shared/gems/ruby/1.9.1/bin/unicorn_rails:23:in load' /var/www/staging/shared/gems/ruby/1.9.1/bin/unicorn_rails:23:in '

VDS has 1.5Gb of RAM and it's enough for unicorn:

cat /proc/meminfo
MemTotal:        1585152 kB
MemFree:          989580 kB
Cached:           425296 kB
Active:           348504 kB
Inactive:         175356 kB
Active(anon):      98488 kB
Inactive(anon):       76 kB
Active(file):     250016 kB
Inactive(file):   175280 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        204800 kB
SwapFree:         204800 kB
Dirty:                12 kB
Writeback:             0 kB
AnonPages:         98564 kB
Shmem:              3604 kB
Slab:              71680 kB
SReclaimable:      66144 kB
SUnreclaim:         5536 kB

I have unicorn_rails v4.5.0

Unicorn starts by following command:

bundle exec unicorn_rails -c /var/www/staging/current/config/unicorn.rb -E production -D

What i'm doing wrong here?


Hmm, i remembered, that previously i had following strange error:

failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.3-p327' -c 'cd /var/www/staging/current && bundle exec unicorn_rails -c /var/www/staging/current/config/unicorn.rb -E production -D'" 

Maybe it is somehow related to memory problems…

like image 526
AntonAL Avatar asked Feb 11 '13 15:02

AntonAL


1 Answers

It seems the error is happening when forking new processes. You may need to reduce the workers in your config/unicorn.rb file. Each worker is a process and each process loads the application environment into the RAM.

like image 161
Diego Carrion Avatar answered Nov 08 '22 09:11

Diego Carrion