Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 try to access it from, are all on a corporate intranet.

like image 488
grautur Avatar asked Apr 12 '11 20:04

grautur


3 Answers

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

like image 59
B Seven Avatar answered Oct 12 '22 22:10

B Seven


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/

like image 30
x10 Avatar answered Oct 13 '22 00:10

x10


I'm late to the party but you can use Thin instead of Webrick.

just add to Gemfile

gem 'thin'
like image 45
stef Avatar answered Oct 13 '22 00:10

stef