Rails 3.2.22.2 + Puma + Heroku 的配置是什么?
What configuration for Rails 3.2.22.2 + Puma + Heroku?
我读过 Richard Schneeman 的文章和其他一些文章。 ;-)
我还在为此苦苦挣扎。
这是我在 Gemfile 中添加的一些 gem,用于对我的应用程序进行基准测试:
gem 'airbrake'
gem 'newrelic_rpm'
gem 'stackprof'
gem 'derailed', group: :development
gem 'rack-mini-profiler'
gem 'flamegraph'
gem 'memory_profiler'
gem "skylight"
在开发和暂存环境中进行了大量基准测试后,我知道我的应用程序哪里不够快,但没有内存泄漏(有时可能会出现一些小的内存膨胀)。
newapp-staging 应用是 oldapp-production[= 的新版本(又名:新前端、升级的 gem、优化的查询……) 45=] 应用程序。
请查看屏幕截图(oldapp-production 使用 webrick,newapp-staging 使用 puma)
所以这里有 2 个简单的问题:
问题 #1
newapp-staging 应用正在使用 ruby '2.2.0' & rails '3.2.22.2' 我无法确保它由于我的代码和相关的 gem,它是线程安全的,所以...我必须一次使用 1 个线程。彪马在这里有优势吗?指标告诉我没有。
或者...我的配置不好。 (可能缺少 preload_app!,或者其他东西?)这是我的 Procfile:
web: bundle exec puma -t 1:1 -p ${PORT:-3000} -e ${RACK_ENV:-development}
worker: bundle exec rake jobs:work
问题 #2
独角兽可以作为替代品吗?
感谢您的宝贵时间和建议。
干杯
在这里使用独角兽是最好的选择。如果可以帮助任何人,这是我的配置。
宝石文件:
gem 'unicorn'
gem 'unicorn-rails'
group :production, :staging do
gem 'unicorn-worker-killer'
end
过程文件:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
config.ru
if ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
require 'unicorn/worker_killer'
use Unicorn::WorkerKiller::MaxRequests, 768, 1024, true
use Unicorn::WorkerKiller::Oom, (450*(1024**2)), (490*(1024**2)), 16, true
end
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run MyApp::Application
在 Heroku 上:
2 x `Standard 2X dynos` for web
1 x `Standard 1X dyno` for worker
Heroku 配置变量:
SENSIBLE_DEFAULTS: enabled
(以防万一) & WEB_CONCURRENCY: 2
干杯
我读过 Richard Schneeman 的文章和其他一些文章。 ;-) 我还在为此苦苦挣扎。
这是我在 Gemfile 中添加的一些 gem,用于对我的应用程序进行基准测试:
gem 'airbrake'
gem 'newrelic_rpm'
gem 'stackprof'
gem 'derailed', group: :development
gem 'rack-mini-profiler'
gem 'flamegraph'
gem 'memory_profiler'
gem "skylight"
在开发和暂存环境中进行了大量基准测试后,我知道我的应用程序哪里不够快,但没有内存泄漏(有时可能会出现一些小的内存膨胀)。
newapp-staging 应用是 oldapp-production[= 的新版本(又名:新前端、升级的 gem、优化的查询……) 45=] 应用程序。 请查看屏幕截图(oldapp-production 使用 webrick,newapp-staging 使用 puma)
所以这里有 2 个简单的问题:
问题 #1
newapp-staging 应用正在使用 ruby '2.2.0' & rails '3.2.22.2' 我无法确保它由于我的代码和相关的 gem,它是线程安全的,所以...我必须一次使用 1 个线程。彪马在这里有优势吗?指标告诉我没有。 或者...我的配置不好。 (可能缺少 preload_app!,或者其他东西?)这是我的 Procfile:
web: bundle exec puma -t 1:1 -p ${PORT:-3000} -e ${RACK_ENV:-development}
worker: bundle exec rake jobs:work
问题 #2
独角兽可以作为替代品吗?
感谢您的宝贵时间和建议。
干杯
在这里使用独角兽是最好的选择。如果可以帮助任何人,这是我的配置。
宝石文件:
gem 'unicorn'
gem 'unicorn-rails'
group :production, :staging do
gem 'unicorn-worker-killer'
end
过程文件:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
config.ru
if ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
require 'unicorn/worker_killer'
use Unicorn::WorkerKiller::MaxRequests, 768, 1024, true
use Unicorn::WorkerKiller::Oom, (450*(1024**2)), (490*(1024**2)), 16, true
end
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run MyApp::Application
在 Heroku 上:
2 x `Standard 2X dynos` for web
1 x `Standard 1X dyno` for worker
Heroku 配置变量:
SENSIBLE_DEFAULTS: enabled
(以防万一) & WEB_CONCURRENCY: 2
干杯