Skip to content

Instantly share code, notes, and snippets.

@justqyx
Last active May 18, 2017 08:27
Show Gist options
  • Save justqyx/ceec3c97be76898e7ad477a2dd56bbb3 to your computer and use it in GitHub Desktop.
Save justqyx/ceec3c97be76898e7ad477a2dd56bbb3 to your computer and use it in GitHub Desktop.
workers by cpu count
#!/usr/bin/env puma
# Ruby 2.2.0+ required
require 'etc'
current_path = 'CURRENT_PATH'
shared_path = 'SHARED_PATH'
directory current_path
rackup "#{current_path}/config.ru"
environment 'production'
pidfile "#{shared_path}/tmp/pids/puma.pid"
state_path "#{shared_path}/tmp/pids/puma.state"
stdout_redirect '#{shared_path}/log/puma_access.log', '#{shared_path}/log/puma_error.log', true
bind 'unix://#{shared_path}/tmp/sockets/puma.sock'
# 根据 CPU 核数来确定 workers 的数量
workers(Etc.nprocessors)
daemonize true
prune_bundler
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = "#{current_path}/Gemfile"
end
@justqyx
Copy link
Author

justqyx commented May 18, 2017

If you are using Ruby < 2.2.0, please use as follow instead.

count = `nproc`.to_i

Note: please ensure you have installed the nproc in your *nix server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment