intermittently slow rails app
I have a Rails app on a Windows machine with a SQL Server database, and mo开发者_StackOverflowst of the time (though not always) it runs painfully slow. Strangely, this has only happened since I migrated the app to a newer machine -- when the app ran on an older machine, it worked fine. I'm not familiar with dealing with servery stuff, so what are things I should be looking at to figure out the problem?
I tried looking at the logs, but they seem incorrect. For example, I'm running the app in production mode, so looking at production.log, I see the following for my last request:
Started GET "/experiments" for 197.57.189.98 at 2011-04-07 12:14:40 -0700
Processing by ExperimentsController#index as HTML
Rendered experiments/_experiment_table.html.erb (5.0ms)
Rendered experiments/_experiment_table.html.erb (13.0ms)
Rendered experiments/_experiment_table.html.erb (3.0ms)
Rendered experiments/_experiment_table.html.erb (2.0ms)
Rendered experiments/_experiment_table.html.erb (2.0ms)
Rendered layouts/_header.html.haml (1.0ms)
Rendered experiments/index.html.erb within layouts/application (5410.5ms)
Completed 200 OK in 5671ms (Views: 500.1ms | ActiveRecord: 5162.5ms)
But it actually took 40 seconds from the time I navigated to "/experiments" to the time the page finished loading. (I'm not sure if the log is including database access time, though?)
This has happened to me. Probably the most critical piece of information missing here is what web server you are using. The Rails log will show you how much time is spent processing a request, but doesn't show how much time it took the web server to pass the request to the rails stack.
There are some instances where an incorrectly configured web server can incur a long timeout delay for a request, for example, doing a reverse DNS lookup that always fails.
You can test this by trying a couple of web servers. In my instance, Webrick was taking 40 seconds for a page load, whereas Passenger on Apache and Thin had no problems. I recommend trying an alternate web server (easy to test from the command line with thin and webrick in particular) to see if the problem goes away.
Then you can debug your web server setup.
精彩评论