Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webrick and Thin are really slow serving static files in Windows. How can I speed them up?

I'm currently developing a web-app, and I alternate between Windows and Mac dev machines for this.

My problem is that pages render extremely slowly on Windows, but it's not my Ruby code running slowly, but rather that static files are getting served slowly.

A typical page takes about 200ms to render and get served in dev (both Mac and Windows are similar here), but it includes about 50 static files (in production it's just 5 to 10, once they get minified and combined, but in dev they're still separate).

Those 50 files take about 1.5 seconds to serve on the Mac, but about 10 seconds on Windows. Which makes it quite tortuous to test things...

I've tried both Webrick and Thin, they are about the same.

Has anybody found this problem and know how to improve this?

I've tried changing the Webrick conf to ":DoNotReverseLookup => true", as suggested in this answer, but it's not helping.

Any help will be greatly appreciated
Thanks!
Daniel

like image 555
Daniel Magliola Avatar asked Nov 28 '13 13:11

Daniel Magliola


2 Answers

You are running into two existential problems that have plagued Ruby developers for a long time:

  • Webrick is slow. Always. Just don't even bother.
  • Ruby is always slower on Windows. Sometimes by orders of magnitude as you've found.

So if you insist on doing development on Windows proper (as opposed to developing only on Linux or developing on a Linux VM running on Windows), then we need to figure out some ways of putting lipstick on a pig.

Some ideas:

  • Make sure you run the latest version of Ruby.
  • Try deploying nginx with Thin as shown in this helpful albeit dated tutorial. This will help you get the most out of Thin's multithreading and asynchronicity.
  • Use Capistrano to deploy to Windows via this also dated GitHub project.

If you do decide you've had enough of developing Rails on an environment it wasn't designed for, you can set up a VM in the manner described here. The author reports significant speedup.

like image 138
Vidya Avatar answered Oct 14 '22 12:10

Vidya


Use an Ubuntu VM inside VirtualBox, it's probably much closer to your deployment environment then mac and windows which means less "but it worked in development" troubles in production.

Also, you will save yourself a lot of time dealing with quirks of different ruby/gems implementations and various levels of headache due to native extensions.

You can:

  1. set up internal network so you can use browser under windows to browse the app running inside the VM
  2. use something like putty to open console sessions to VM
  3. share a Dropbox/Sparkleshare folder with your Ubuntu VM so you always have same code between Windows and Mac box and Ubuntu VM
  4. and this enables you to use your favorite editor under windows/macos to edit files inside the VM
  5. you can use that same VM under Mac too

Ubuntu installation under VirtualBox is fast, easy and well documented, it's pretty much just a wizard. Alternatively, you can try finding a good vagrant recipee (see http://www.vagrantup.com/) or ask around to see if a colleague of yours would be willing to share his/her vbox.

like image 24
bbozo Avatar answered Oct 14 '22 10:10

bbozo