Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 is very slow in development-mode because of assets, what to do?

After I added Sprockets, Rails is loading very slow in development mode, what should I do to speed it up?

like image 409
jonepatr Avatar asked Sep 22 '11 23:09

jonepatr


2 Answers

Take a look at https://github.com/wavii/rails-dev-tweaks.

Rails is running all of the to_prepare hooks on every Sprockets asset request in development mode. This includes things like auto-(re)loading your code, and various gems sneak work in there too.

rails-dev-tweaks disables to_prepare & reloading on any asset request (and a few others - read the first part of its README). Speeds up your dev environment by a huge amount for any decently sized project. It's also configurable to do this for any additional requests you like

like image 121
Nevir Avatar answered Oct 11 '22 07:10

Nevir


After referring to several Google results regarding this issue, I've nailed down where the DNS issue resides.

The problem is: Rails is doing reverse lookups. So, if you request from a direct IP, or a hostname in the /etc/hosts of only the machine with the browser, which i do often because i run everything in thrown together VM's, and that IP doesn't resolve to something quickly in the dev server, Rails will wait, for each, and every request.

Moral of the story? Include a /etc/hosts entry for every IP related to your development on the dev server (i.e. the server running rails). This means to go ahead and make a hosts entry for every fake/virtual/etc... IP on the dev server you expect to be involved in rails testing, because when it logs requests and whatnot, it will do a reverse lookup, and you want that to be speedy.

like image 45
Randy Wallace Avatar answered Oct 11 '22 07:10

Randy Wallace