【问题标题】:What configuration for Rails 3.2.22.2 + Puma + Heroku?Rails 3.2.22.2 + Puma + Heroku 的配置是什么?
【发布时间】:2016-04-30 11:19:51
【问题描述】:

我已经阅读了 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、优化的查询……)。 请看截图(oldapp-production 使用 webrick,newapp-staging 使用 puma)

所以这里有两个简单的问题:

问题 #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

可以用独角兽代替吗?

感谢您的宝贵时间和建议。

干杯

【问题讨论】:

    标签: ruby-on-rails-3 heroku puma


    【解决方案1】:

    使用独角兽是最好的选择。如果这可以帮助任何人,这是我的配置。

    宝石文件:

    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

    干杯

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 2016-08-21
      • 2013-07-28
      • 2020-01-05
      • 2016-08-06
      • 2020-04-09
      • 2023-02-02
      • 1970-01-01
      • 2016-10-10
      相关资源
      最近更新 更多