监测缓慢的nginx /独angular兽请求

目前我正在使用Nginx将请求代理到运行Sinatra应用程序的Unicorn服务器。 应用程序只定义了几条path,这些path对PostgreSQL数据库进行相当简单的(非昂贵的)查询,最后以JSON格式返回数据,这些服务都由上帝监视。

我目前正在经历从这个应用程序服务器响应时间非常缓慢。 我有另外两个通过Nginx代理的Unicorn服务器,而且这些服务器的响应非常好,所以我认为我可以排除Nginx中的任何错误。

这是我的上帝configuration:

# God configuration APP_ROOT = File.expand_path '../', File.dirname(__FILE__) God.watch do |w| w.name = "app_name" w.interval = 30.seconds # default w.start = "cd #{APP_ROOT} && unicorn -c #{APP_ROOT}/config/unicorn.rb -D" # -QUIT = graceful shutdown, waits for workers to finish their current request before finishing w.stop = "kill -QUIT `cat #{APP_ROOT}/tmp/unicorn.pid`" w.restart = "kill -USR2 `cat #{APP_ROOT}/tmp/unicorn.pid`" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.pid_file = "#{APP_ROOT}/tmp/unicorn.pid" # User under which to run the process w.uid = 'web' w.gid = 'web' # Cleanup the pid file (this is needed for processes running as a daemon) w.behavior(:clean_pid_file) # Conditions under which to start the process w.start_if do |start| start.condition(:process_running) do |c| c.interval = 5.seconds c.running = false end end # Conditions under which to restart the process w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = 150.megabytes c.times = [3, 5] # 3 out of 5 intervals end restart.condition(:cpu_usage) do |c| c.above = 50.percent c.times = 5 end end w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end 

这是我的独angular兽configuration:

 # Unicorn configuration file APP_ROOT = File.expand_path '../', File.dirname(__FILE__) worker_processes 8 preload_app true pid "#{APP_ROOT}/tmp/unicorn.pid" listen 8001 stderr_path "#{APP_ROOT}/log/unicorn.stderr.log" stdout_path "#{APP_ROOT}/log/unicorn.stdout.log" before_fork do |server, worker| old_pid = "#{APP_ROOT}/tmp/unicorn.pid.oldbin" if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH # someone else did our job for us end end end 

我已经检查了上帝的状态日志,但它似乎CPU和内存使用情况永远不会出界。 我也有一些杀死高内存的工作,这可以在这里的GitHub博客页面find 。

当在独angular兽的日志上运行一个tail -f时,我看到一些请求,但是在这个问题似乎已经到来之前,我每秒大约在60-100之间时,他们之间的差距很小。 这个日志还显示工人正在收获,并按预期启动。

所以我的问题是,我将如何去debugging呢? 我应该采取的下一步措施是什么? 我非常困惑,服务器有时会迅速响应,但在其他时间,它很慢,很长一段时间(这可能是也可能不是高峰stream量时间)。

任何意见,非常感谢。

我将首先看看像atop这样的工具在一般的系统健康状况。 接下来,我会仔细看看postgres在做什么 。 如果没有发现问题,我会使用tcpdump(或者更好的tshark )查看浏览器,ngnix和独angular兽之间的通信。 与此同时,我会尝试nginx和独angular兽strace 。