Skip to content

Instantly share code, notes, and snippets.

@jonkgrimes
Last active November 18, 2016 18:44
Show Gist options
  • Save jonkgrimes/5103321 to your computer and use it in GitHub Desktop.
Save jonkgrimes/5103321 to your computer and use it in GitHub Desktop.
Unicorn.rb for keen.io configuration
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server,worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server,worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
if defined?(EventMachine)
unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
if EventMachine.reactor_running?
EventMachine.stop_event_loop
EventMachine.release_machine
EventMachine.instance_variable_set("@reactor_running",false)
end
Thread.new { EventMachine.run }
end
end
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
end
@samnang
Copy link

samnang commented May 11, 2014

Above configuration works great for Unicorn + EventMachine, but every time either new deploy or restart heroku process, it prints out a lot of errors in the log https://gist.github.com/samnang/8536882bc16eebfdcc29

@juliosantos
Copy link

Same issue with Heroku here.

@arturodz
Copy link

Same thing here with Heroku + Rails

@dsmontoya
Copy link

WARNING: Detected 2 Thread(s) started in app boot:
2015-03-26T00:07:54.952008+00:00 app[web.1]: [3] ! #<Thread:0x007f020a082d08 sleep> - /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent/event_loop.rb:118:in select' 2015-03-26T00:07:54.952030+00:00 app[web.1]: [3] ! #<Thread:0x007f020ac92cb0 sleep> - /app/vendor/bundle/ruby/2.1.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:inrun_machine'

@k2xl
Copy link

k2xl commented Nov 18, 2016

issue still happens

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