Speeding up the rails 3 development server - ruby-on-rails

Now that Rails 3 is out, my favorite dev-mode plugin (rails-dev-boost) is broken. I'm working on a large application (>100 models and controllers) and loading them all every request takes more than ten seconds. I could turn config.cache_classes on, but then I might as well run in production mode since I have to restart the server every change.
Is there something out there that could speed this up?

That plugin owner (rails-dev-boost) is working on getting it running with rails3, so hopefully soon!
I sure wish rails did that kind of stat-optimization out of the box!
https://github.com/thedarkone/rails-dev-boost
Here's the link to the rail3 branch (might disappear if/when the updates are moved into the core release)
https://github.com/thedarkone/rails-dev-boost/tree/rails3

Related

Dockerized Rails 5 RC1 application not picking up updates to controllers and models in development

I have quite a bit of experience developing Rails 4 apps on Mac OS X + Docker Machine + Docker Compose, but something has changed with how Rails 5 is caching files in the development environment (currently testing with RC1).
After starting the application with docker-compose up, the application runs normally in development mode.
But if I make a change to a controller or model, the only way I can get that reflected in the application is to stop the server and start it back up.
So now my workflow looks something like this when I need to make a change to a controller or model:
Make change to controller/model class.
Stop server with Ctrl + C.
Start server back up with docker-compose up.
Wait on the server to start up.
Run whatever I was running in the browser.
To say the least, needing to do steps 2-4 is annoying and not what I'm accustomed to from Rails 4.
I went a step further and uninstalled Spring using the Removal instructions, but I still get the same behavior.
I also searched for any settings that I could find in config/environments/development.rb related to the Rails runtime's iron grip on the model and controller classes, and I couldn't find anything. (I assume that it really wants to rely on watching the filesystem in order to selectively load changes, and something isn't being picked up from a change on Mac to VirtualBox.)
Any other ideas on what I can try? Or are there any new settings related to how this more aggressive caching works?
I'm Using Rails 5 rc1.
Rails 5 introduced some "improvements" to code reloading, but it doesn’t seem to work with Docker on OS X.
So in config/environments/development.rb, I replaced
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
with
config.file_watcher = ActiveSupport::FileUpdateChecker
It seems that for the ActiveSupport::EventedFileUpdateChecker file watcher, the change event does not occur for docker-machine shared files

Rails observer causes slow processing time in development mode

I'm on Rails 3.1.1 and I have noticed my app has become exceedingly slow (15 seconds) in development mode. See my firebug 'Net' listing below:
I've done a number of things like:
reducing the number of gems
turning class caching on
turning asset debugging to false
turning asset compression to true
installing the rails-dev-boost gem
Maybe there were some improvements, but nothing helped it to go as fast I'd expect when running off localhost. That is, until I commented out my observers config line in application.rb:
config.active_record.observers = :item_observer, :loan_observer, :friendship_observer, :message_observer, :user_observer
And then the app was fast again (~1 sec) load time. See the firebug listing now:
Other notes:
When in production on Heroku, it's fast (~1 sec), as you'd expect.
I'm using postgresql and Thin; I have not tried using other DBs to see if this problem exists.
When I commented out just the last observer, user_observer, the load time dropped by about half.
The load times printed in development.log do not reflect actual load times. Assets were flagged as 304 Not Modified (0ms) they really took a while to load.
Yes, I'm using the asset pipeline
The Golden Question: Is the simple act of registering observers causing assets to load slowly? And what can be done about it?
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 perform work in there too. And in your case, observers are being registered (which - I believe - causes Rails to reference a good portion of your app in order to reference the models)
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
The way I am fixing this is refactoring the observers into concerns. https://gist.github.com/1014971

Is there a way for a ruby on rails app to support web-based upgrades like Wordpress does?

I've been using Wordpress for awhile, it's installed on my own server, and one of the features I most love about it is how every time there is a new version it alerts you within the app's web-based admin and with one click I can upgrade the app. I don't have to get anywhere near a console.
Personally I wouldn't mind updating manually, but I can see how this could significantly affect the adoption of a piece of software. I'm working on creating a full-featured ruby on rails forum software and I would love to figure out how to include this feature. Any ideas if this could be done with rails?
Could a rails app modify it's own files? If it did, would the server need to be restarted?
To complicate things further, what if the app was deployed from a repo. Could the rails app check in a commit of itself after updating?
Maybe packaging the core of the app as a gem would be simpler? Then maybe the upgrade would not actually modify the rails MVC stack (the rails app would just be super-basic), instead if the forum was all contained within a gem then all it has to do is trigger a 'gem update [name]'. If this occurred, I don't think the Gemfile would even need to be updated. Would a server restart even be required to load the updated gem?
Ideas or feedback on any of this?
Rails files can be modified and even deleted on production - in my case aplication is still working unchanged as all classes are cached in memory. It means Rails instances must be restarted to take new change.
I suppose WordPress is Perl via CGI and you just drop application into web directory to have it working immediately - same with updates - just overwrite files and Apache picks them up immediately.
In case of Rails is that you don't know target deployment architecture thus restarting application may not be trivial. E.g. with passenger I can just do touch tmp\restart.txt and then all instances are killed and started again. Some deployments may need init.d script restart invocation.
Maybe you could recommend or prepare a ready to use deployment model which supports autoupdate. In other cases users could do updates manually.

Can Ruby on Rails cache a Controller "as long as code is not changed"?

At work, we have a situation where when
script/server
is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.
So we can turn off the caching of controller code all together. But
can't there be mechanism that is similar to the inclusion of javascript
foo.js?1275647624 <--- UNIX timestamp
which is to use the cached version as long as there is no code change,
but recompile it when there is code change?
Maybe because we use HAML and SASS a lot, loading some page (such as the
homepage of the site) can take 40 seconds on the dev environment and it
is quite long.
By default Rails will reload your classes for every request in the development environment. This should ensure that any changes are picked up. Classes are usually only cached when running in the production environment, or possibly if you have a staging environment set up.
Obviously I don't know your application, but 40 seconds to load a home page in development sounds like a long time. Are there any errors in the log?

How did this Ruby on Rails app get deployed?

I have a Ruby on Rails app running on my server, and I can't figure out how it was deployed (someone else set it up).
The app is located in /var/www/myapp. Before it was deployed, I had been able to go in there and make minor edits to the app. The person helping me out with RoR then "deployed" it. It was unclear what deploying actually did, since it points to the same database and is on the same server. However, I can no longer edit it (or at least, the files I am editing are not being pointed to by the server).
Any way to figure out how this thing was deployed so I can take it down to edit it? Or should I basically just start over?
Was it maybe running in development mode before, and now it's in production? When it's in development mode, all of the files are loaded on each request, so your changes show up immediately. In production mode, you have to restart the server to see your changes.

Resources