Unicorn take 100% CPU

March 27, 2014 2.5k views
I was deploy rails aplication on the basic droplet. There are nginx, ruby 2.0.0 through rvm, rails 4.0.1, foreman. All of this deploy with capistrano 3. When I start unicorn instances, they take all of the free CPU and CPU load is 100% whole time untill unicorn work. There is my unicorn.rb: worker_processes 4 working_directory "/var/www/apps/estate/current" # available in 0.94.0+ listen "/var/www/apps/estate/socket/.unicorn.sock", :backlog => 64 listen 8080, :tcp_nopush => true timeout 30 pid "/var/www/apps/estate/run/unicorn.pid" stderr_path "/var/www/apps/estate/log/unicorn.stderr.log" stdout_path "/var/www/apps/estate/log/unicorn.stdout.log" preload_app true GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true check_client_connection false before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH end end end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end What might be wrong with my settings?
2 Answers

I had the same problem.
In my case it was some gems missing.
After I installed them Unicorn took up not more than 0.3% CPU.

The problem was unclear since unicorn error log file didn't show me anything. I tried to run Thin server instead and got nice "Can't load" errors in its logs.

Try using NewRelic or a similar service to find out where the bottleneck is, they offer a 14-day free trial.
Have another answer? Share your knowledge.