2

When i open a Ruby http server locally, i. e. via http://localhost:4567, it takes little time to load the page:

  • ruby -run -e httpd . -p4567, directory listing — instantaneous;
  • ruby -run -e httpd . -p4567, a heavy jpeg — instantaneous;
  • middleman server, refreshing a previously opened website — ~5 seconds.

But when i do the same over LAN, it takes substantially longer to load the page. I tried it from two remote machines: a mobile phone over WiFi and a virtual machine running on the same host machine as the web server (using a virtual network adapter).

  • ruby -run -e httpd . -p4567, directory listing — ~5 seconds;
  • ruby -run -e httpd . -p4567, a heavy jpeg — ~5 seconds to start downloading the image, then loads it almost instantaneously;
  • middleman server, refreshing a previously opened website — 15—30 seconds, may cause a timeout on mobile.

What can be the cause of this and how can it be resloved?

PS The host machine is Windows 7 but it seems to work both ways, i. e. when the server runs on a Linux virtual machine.

Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133

1 Answers1

0

Ok, it turned out to be an issue with Webrick.

This quesition/answer is a duplicate of: Webrick is very slow to respond. How to speed it up? Below is an abstract of answers from the linked page.

Possible solutions (pick one):

  1. Use Thin instead of Webrick if possible (Thin is not available on Windows and might be unavailable for your specific project). Any other Ruby web server might also fit.
  2. If you're stuck with Webrick, instantiate it in your project by passing DoNotReverseLookup: true to WEBrick::HTTPServer.new.
  3. If for some reason you're unable to modify how your project leverages Webrick, you can hack Webrick source. Find the webrick/config.rb file in your system and set the :DoNotReverseLookup parameter to true. You'll have to repeat this step every time you update your dependency.
  4. On Linux, you can stop the avahi-daemon service to resolve the issue. Note that it will also prevent network printers and shares from being automatically discovered.
Community
  • 1
  • 1
Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133