我刚刚在Unicorn上部署了一个Rails 4应用程序.
它没有流量,在我看来,它正在吃大量的内存.
与2名独角兽工人闲置,使用253 MB的ram.这是预期的吗?
我使用一些可能是内存饥饿的宝石,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'
对于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
独角兽工人每人出现三次.它是否正确?
来自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]
您是否需要更多信息来告诉我这是否是高内存消耗?
解决方法
这是完全正常的,每个独角兽工人都是一个独立的过程.
你看到三个过程,因为你要求两个工人.因此,您拥有生成工作者并响应用户信号的主进程,另外两个是实际的工作进程.
拥有这样的隔离进程会消耗更多的内存,但实际上非常酷:它允许进行优雅的重启,让一些工作人员立即关闭,其他人保持活着直到他们完成处理他们的请求.
另请注意,当您进行正常重启(USR2信号)时,您通常的内存消耗将在短时间内翻倍.这是因为新的主服务器开始接受新的请求,产生自己的工作程序,并且在所有工作程序完成处理请求之前,以前的主服务器不会关闭.
编辑:回答每个进程使用的ram数量,这也没关系.我的工作应用程序每个进程消耗大约315MO.一个预发布方项目的宝石数量与您的宝石差不多,每个流程大约280MO.