Last active
May 18, 2017 08:27
-
-
Save justqyx/ceec3c97be76898e7ad477a2dd56bbb3 to your computer and use it in GitHub Desktop.
workers by cpu count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are using Ruby < 2.2.0, please use as follow instead.
Note: please ensure you have installed the
nproc
in your *nix server.