I have a Rails application (3.2) that runs on nginx and the unicorn on the cloud platform. Box works on Ubuntu 12.04.
When the system load is about 70% or higher, nginx suddenly (and seemingly by accident) starts throwing 502 "bad gateway" errors ; when the load is less, nothing like that. I experimented with a different number of cores (4, 6, 10 - I can "change equipment" like on a cloud platform), and the situation is always the same. (CPU usage is similar to system loading, user area is 55%, the rest of the system is stolen, with lots of free memory, without sharing).
502 usually come in batches, but not always.
(I run one unicorn worker per core and one or two nginx workers. See the relevant sections of the configurations below for 10 cores.)
I really don't know how to track the cause of these errors. I suspect this may have something to do with unicorn workers who can't serve (on time?), But it looks weird because they don't seem to saturate the CPU and I see no reason why they will wait for input - output (but I donβt know, I donβt know how to do this).
Could you help me find the reason?
Unicorn Configuration ( unicorn.rb ):
worker_processes 10 working_directory "/var/www/app/current" listen "/var/www/app/current/tmp/sockets/unicorn.sock", :backlog => 64 listen 2007, :tcp_nopush => true timeout 90 pid "/var/www/app/current/tmp/pids/unicorn.pid" stderr_path "/var/www/app/shared/log/unicorn.stderr.log" stdout_path "/var/www/app/shared/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| ... I believe the stuff here is irrelevant ... end after_fork do |server, worker| ... I believe the stuff here is irrelevant ... end
And config ngnix:
/etc/nginx/nginx.conf :
worker_processes 2; worker_rlimit_nofile 2048; user www-data www-admin; pid /var/run/nginx.pid; error_log /var/log/nginx/nginx.error.log info; events { worker_connections 2048; accept_mutex on;
/etc/nginx/conf.d/app.conf :
sendfile on; tcp_nopush on; tcp_nodelay off; gzip on; gzip_http_version 1.0; gzip_proxied any; gzip_min_length 500; gzip_disable "MSIE [1-6]\."; gzip_types text/plain text/css text/javascript application/x-javascript; upstream app_server {