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

3

8

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

Chastise answered 28/11, 2013 at 13:24 Comment(9)
You can try setting it up in a Linux VM, more often than not this can actually be faster.Sausage
cdn.sstatic.netPathogen
could you write more details about "Those 50 files"? Are the files CSS-Files, JavaScript files, JPG files, PNG files or some other... From where you load the files? If the files are loaded from some web server then it could be important whether you set any caching options in HTTP header. It's helpful to use Fiddler or some other tools to trace HTTP traffic during the 10 seconds on Windows. You can upload the traffic as the file and include the URL to the trace. In the case other could analyse it.Cuprite
@AlexanderKosubek that would be massively overkill to implement and very hard, given that the problem happens only in dev. Also, the CSS files are originally SCSS, and need to get magically pre-processed when they change, so not sure I can pull that off with a separate web server for static files. (And no, the pre-processing is not the problem, it only happens when files change, and the delay happens in every web page hit)Chastise
@Cuprite Thank you for your answer. These are CSS files, JS files and PNG files, basically. They are loaded from the web server, and they don't have an Expires header in dev because they change. (in production they do, but the problem is only in dev). The problem is not that i'm loading files that I shouldn't be loading (although that could be a side, and very complicated way of fixing the issue). The problem is that Webrick is ridiculously slower serving static files on Windows than on MacOsX, and I'm trying to see if I'm missing something stupid that could speed that up.Chastise
@DanielMagliola: There are a lot of standard tricks which you can use to improve performance. For example multiple files (CSS files, JS files or even PNG files) can be combined in one file of the same type. It can improve the performance. The most important is to understand what will be done in the 10 seconds. So the trace of HTTP traffic could be really helpful. By the way do you tried to use Google Chrome on Windows? Do you have the same 10 sec. or less?Cuprite
What browser are you using? What version of Windows?Nerve
I'm using Google Chrome, Windows 7 64-bit, ruby 1.9.3p194. Combining files is possible (and we do do it in production), but it adds a lot of "compilation" time to every request, which would make it even worse. What I'm aiming at is... "Serving all these files is very quick in Linux, and very slow in Windows. Is there anything I can do about it?"Chastise
I think you need to provide a little more info here. I did a Rails install (rails v3.2.13, ruby 1.9.3p392) on a clean Windows 7 64-bit machine. I set up webrick to point to a local static web site. I then accessed the site from another machine and had the bad performance you are seeing. Then I updated my webrick config, per the answer you linked to. My performance issues went away. I also created a rails application using my static web site. I had the same results as the webrick site.Nerve
A
2

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.

Arkansas answered 8/12, 2013 at 22:38 Comment(0)
N
1

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.

Nonlegal answered 4/12, 2013 at 19:51 Comment(0)
K
0

I experienced a performance decrease on development (due to real-time compilation) working with projects with a large number of assets, but I was not on Windows.

I assume the large performance difference may be caused by some inefficient asset compilation under Windows.

I don't any Windows development experience, I haven't been using a Windows machine for a long time, however I registered a noticeable performance increase in parallel asset processing (in development) when I switched to multi-thread servers, specifically Puma. Keep in mind that, in any case, the default Rails webserver (Webrick) is very inefficient.

As Konstantine explained in this answer, there are currently several choices available. You can group them by the processing mode.

Skipping all the background history about Ruby threads, multi-process etc, I'd invite you to try Puma in your machine and see if it improves the load.

Puma works better with Ruby implementations that offer real multi threading, but quoting the official readme

On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Puma is designed to provide a simple and high performance request/response pipeline to Rack apps.

Kuo answered 4/12, 2013 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.