rails app fast on server, but slow when accessed from another machine
I have a Rails app hosted on a server machine (running Webrick). When I log onto this machine and access the app (via localhost:3000), the app runs smoothly. But when I try to access the app from another machine (via hostname:3000), the app runs super slowly.
I'm not sure how to go about debugging the problem; is there any reason why this would be the case? I also have things like a SQL server database hosted on the same server machine, and accessing the database from other machines works fine.
Updating to add: the server machine, and the other machines I t开发者_如何转开发ry to access it from, are all on a corporate intranet.
The following answer worked for me. Note that if you are running rvm the answer is at the bottom.
Webrick is very slow to respond. How to speed it up?
Look for the file /usr/lib/ruby/1.9.1/webrick/config.rb
and edit it.
Replace the line
:DoNotReverseLookup => nil,
with
:DoNotReverseLookup => true,
rvm file is ~/.rvm/rubies/ruby-your-version/lib/ruby/your-version/webrick/config.rb
The most obvious answer would be that the problem is not with rails, but with your Domain Hosting(i.e. your DNS is super slow).
Try and load a different app(maybe a Sinatra "hello world") and see if it exhibits the same symptoms.
If yes - your domain provider is to blame.
If the problem persists, increase the verbosity of the logs and check if any SQL queries are an obvious bottleneck.
Also, the problem may be with Webrick. It just wasn't meant for production and may be slow if several people use the app at once. Try it with a different server. Apache is a reasonable choice: http://www.modrails.com/
I'm late to the party but you can use Thin instead of Webrick.
just add to Gemfile
gem 'thin'
Webrick isn't the fastest in the world, I'm fairly positive it's not meant for production but rather local testing. When you're connecting to the other machine is it on a local network or over the internet?
Take a look at the response times listed in your rails log file. If they are the same for local and remote access, then you know your problem is somewhere else in the stack (DNS, routing, software firewall, etc.)
It's highly likely that the problem is not rails itself.
精彩评论