Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Configuration Puma

ZeroC0D3 Team edited this page Jan 19, 2018 · 5 revisions

Configuration for Puma

Configuration for Puma Development / Staging

# config/puma/staging.rb
require "active_record"
  
root = "/home/deploy/zeroc0d3lab.dev/current"

# Default to staging
rails_env     = ENV['RAILS_ENV'] || "staging"
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 4)
environment rails_env

pidfile           "#{ root }/tmp/pids/puma.pid"
stdout_redirect   "#{ root }/log/puma.log"
bind              "unix://#{ root }/tmp/sockets/puma-staging.socket"
state_path        "#{ root }/tmp/pids/puma.state"
rackup            DefaultRackup
port              ENV['PORT'] || 3000

daemonize         true
workers           Integer(ENV['WEB_CONCURRENCY'] || 2)
threads           threads_count, threads_count
worker_timeout    90

# bind 'tcp://0.0.0.0:9292'
# bind 'unix:///var/run/puma.sock'
# bind 'unix:///var/run/puma.sock?umask=0111'
# bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'

# ssl_bind '127.0.0.1', '9292', {
#   key: path_to_key,
#   cert: path_to_cert
# }

preload_app!

on_worker_boot do
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{ root }/config/database.yml")[rails_env])
end

Configuration for Puma Production

# config/puma/production.rb
require "active_record"
  
root = "/home/deploy/zeroc0d3lab/current"

# Default to production
rails_env     = ENV['RAILS_ENV'] || "production"
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 4)
environment rails_env

pidfile           "#{ root }/tmp/pids/puma.pid"
stdout_redirect   "#{ root }/log/puma.log"
bind              "unix://#{ root }/tmp/sockets/puma-production.socket"
state_path        "#{ root }/tmp/pids/puma.state"
rackup            DefaultRackup
port              ENV['PORT'] || 3000

daemonize         true
workers           Integer(ENV['WEB_CONCURRENCY'] || 2)
threads           threads_count, threads_count
worker_timeout    90

# bind 'tcp://0.0.0.0:9292'
# bind 'unix:///var/run/puma.sock'
# bind 'unix:///var/run/puma.sock?umask=0111'
# bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'

# ssl_bind '127.0.0.1', '9292', {
#   key: path_to_key,
#   cert: path_to_cert
# }

preload_app!

on_worker_boot do
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{ root }/config/database.yml")[rails_env])
end

Get CPU Info

  • Linux
    grep -c processor /proc/cpuinfo
    
  • OS-X
    sysctl -n machdep.cpu.brand_string   
    sysctl -a | grep machdep.cpu | grep core_count  
    sysctl -a | grep machdep.cpu | grep thread_count
    

Troubleshoot MacOS

objc[1594]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[1595]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[1594]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. # We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
  • Run or add into ~/.bashrc or ~/.zshrc
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Using binding.pry

  • Install gem pry-remote
    gem install pry-remote
  • You can add also into Gemfile
    group :development, :test do
      gem 'byebug'
      gem 'binding_of_caller'
      gem 'pry-rails'
      gem 'pry-remote'
      gem 'annotate'
    end
  • Install your bundle
    bundle install
  • Remove or comment on line:
    #stdout_redirect   "#{ root }/log/puma.log"
  • Restart your puma server
    bundle exec rails s puma      # or
    bundle exec rails s puma RAILS_ENV=development 
Clone this wiki locally