views:

57

answers:

2

I have a rails app (2.3.5) running on a VPS with 4 cores @ 2 GHz and 4GB memory. I am running nginx (0.7.61) and phusion passenger(2.2.14) on Ruby Enterprise (1.8.7-2010.01) with the max pool size set at 30. My problem is that it seems as if every ruby process that is executing a rails request runs at near 100% cpu. If I run TOP they drop off every time the display refreshes so they are not getting hung, but they are still running at 100%.

Is there any way I can bring this down? Or at least figure out what portion of code is spiking the CPU? Is this a normal behavior?

Here is the TOP output:

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                     
 2427 psadmin   25   0 91904  76m 2696 R  100  1.9 739:05.96 Rails: /var/www/apps/main_rails_app/current                                                                                                  
 3457 psadmin   25   0 98180  82m 2532 R  100  2.0 711:21.91 Rails: /var/www/apps/main_rails_app/current                                                                                                  
 2415 psadmin   25   0 93952  77m 2708 R   99  1.9 727:49.31 Rails: /var/www/apps/main_rails_app/current                                                                                                  
 3455 psadmin   25   0 99204  83m 2528 R   69  2.0 726:04.70 Rails: /var/www/apps/main_rails_app/current                                                                                                  
 2791 psadmin   16   0 98044  81m 2492 S   31  2.0   0:10.16 Rails: /var/www/apps/main_rails_app/current                                                                                                  
 8034 psadmin   15   0  8160 3656 1772 S    1  0.1   0:35.39 nginx: worker process                                                                                                                        
 8035 psadmin   15   0  8324 3696 1732 S    0  0.1   0:31.34 nginx: worker process                                                                                                                        
 2588 psadmin   15   0  197m 183m 2712 S    0  4.5   1:02.16 Rails: /var/www/apps/main_rails_app/current      

Thanks!

Edit: Tried strace with follow forks as mentioned below. This is the output that is dumped over and over:

sudo strace -f -p 3455

clock_gettime(CLOCK_MONOTONIC, {394577, 508326476}) = 0
select(0, [], [], [], {0, 0})           = 0 (Timeout)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()   
+1  A: 

check your logs for suspicious behavior. In general rails does suck a bunch of cpu though...you could also try pointing strace at the offending pids.

rogerdpack
I've tried strace but it never shows any output, just that it is bound to that PID. I think it may be because the pid doesn't exist for very long, but while it does it is at 100%.
bwizzy
make sure you're following forks (-f or -F or something). Or try a different pid :)
rogerdpack
A: 

Hi, I'm having the same issue on two different servers using:
Rails 2.3.5
passenger 2.2.5
ruby 1.8.7 (2009-12-24 patchlevel 248) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2010.01

Do you know what the problem is and how to fix it?
Thanks.

mazhout