Unicorn take 100% CPU

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/”

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 != begin sig = ( + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, 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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.