Skip to content

Instantly share code, notes, and snippets.

@Hengjie
Created January 25, 2013 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hengjie/4633113 to your computer and use it in GitHub Desktop.
Save Hengjie/4633113 to your computer and use it in GitHub Desktop.
Minimize Unicorn worker_processes in 'development' env
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
# Save on RAM while in development
if environment == 'development'
worker_processes 1
else
worker_processes 4
end
timeout 30
preload_app true
before_fork do |server, worker|
# Close all open connections
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
@resque_pid ||= spawn("bundle exec rake resque:work QUEUES=fast")
end
after_fork do |server, worker|
# Reopen all connections
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment