rails app fast on server, but slow when accessed from another machine
Asked Answered
M

5

7

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.

Mossbunker answered 12/4, 2011 at 20:51 Comment(1)
I am having the same issue. It's not Rails and it is not DNS because I am accessing using IP. Ping is fast: 0.04ms.Carlos
R
4

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/

Reena answered 12/4, 2011 at 20:54 Comment(3)
Hmm, yep, thanks!, it looks like it's a DNS problem -- accessing via the IP address directly (as opposed to the hostname) works fine, and a Sinatra "hello world" is also super slow (when accessing via hostname). But if it's a DNS problem, shouldn't pinging the hostname also be super slow? (Pinging the hostname seems to work fine, so I'm a bit confused.)Mossbunker
Eh, I wouldn't know about that :) You asked a Rails question and got an answer from a guy interested in Rails. You should close this question and open a different one for what you now know to be a different problem.Reena
As a note on the ping response, don't trust it for lookup speed. On some operating systems, the ping may be using cached DNS while rails may be doing the lookup every time.Megavolt
C
14

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

Carlos answered 14/6, 2011 at 18:29 Comment(0)
R
4

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/

Reena answered 12/4, 2011 at 20:54 Comment(3)
Hmm, yep, thanks!, it looks like it's a DNS problem -- accessing via the IP address directly (as opposed to the hostname) works fine, and a Sinatra "hello world" is also super slow (when accessing via hostname). But if it's a DNS problem, shouldn't pinging the hostname also be super slow? (Pinging the hostname seems to work fine, so I'm a bit confused.)Mossbunker
Eh, I wouldn't know about that :) You asked a Rails question and got an answer from a guy interested in Rails. You should close this question and open a different one for what you now know to be a different problem.Reena
As a note on the ping response, don't trust it for lookup speed. On some operating systems, the ping may be using cached DNS while rails may be doing the lookup every time.Megavolt
C
3

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

just add to Gemfile

gem 'thin'
Cardio answered 10/1, 2013 at 12:50 Comment(0)
F
1

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?

Fulvous answered 12/4, 2011 at 20:56 Comment(1)
When I connect to the other machine, it's on a local network. (Both machines are on a corporate intranet.)Mossbunker
M
1

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.

Megavolt answered 13/4, 2011 at 3:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.