Skip to content

Instantly share code, notes, and snippets.

@groundwater
Last active December 23, 2015 11:29
Show Gist options
  • Save groundwater/6628306 to your computer and use it in GitHub Desktop.
Save groundwater/6628306 to your computer and use it in GitHub Desktop.

Enumerating Unicorn Workers

Usage

unicorn -c unicorn.conf.rb
# require another part of our app
require "./worker"
# load some webapp
# can be anything
app = lambda do |env|
[
200,
{ 'Content-Type' => 'text/html' },
'Hello World'
]
end
run app
# start 20 child processes
worker_processes 20
after_fork do |server, worker|
# assign the worker number to a global variable
$nr = worker.nr
end
# from a child, pull the global variable to get the number
puts "#{Process.pid} => #{$nr}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment