Using Zeus to Pre-load Ruby on Rails Environments

Critics of Ruby on Rails often accuse it of being slow. The standard rebuttal is that any web application scales given enough instances, but that rebuttal ignores one important effect of Rails’ slowness: the impact on development. Any time you run a Rails command, Rails loads your entire project, a process that starts out slow and slows down as your project grows.

If you’ve been irritated by these startup delays, you’re not the only one, and there’s finally a way to wait less and do more. Its name is Zeus.

You can gem install zeus, then start the server with zeus start. Zeus’ server spawns several processes in parallel, processes for the Rails server, the console, for RSpec, Cucumber, and any others that you specify.

Zeus loads the Rails environment for each process but doesn’t execute any commands. To execute a command under a preloaded environment, use the zeus command in place of the rails command, as in zeus console or zeus generate model SolarSystem. These commands connect to the Zeus server and use the preloaded process, starting your command within a second or two regardless of the size of your application. As you make changes to your application’s code, Zeus reloads processes that depend on the files you’ve modified, keeping your preloaded environments up to date with your latest code.

While Zeus was developed for speeding up Rails’ commands, it is intended to be platform agnostic and suitable for preloading slow processes of other systems as well. Personally, I’m interested to see how well it speeds up JRuby load times, which have the added burden of the JVM’s startup delay.

As handy as Zeus is, it isn’t perfect. You’ll undoubtedly find situations where a command run through Zeus behaves differently than its counterpart Rails command. In such cases, you can fall back to using the Rails command without losing any of the commands that behave correctly. Also, Zeus’ creator Burke Libbey is actively improving Zeus and is responsive to issues filed on the Zeus GitHub page.
 

Conversation
  • Felipe says:

    This error generally hanepps when you accidentally recursively changing an attribute. If you have a username attribute in User model, and a virtual attribute named username, that is directly changing the username, you end up calling the virtual, the virtual calls the virtual again and so on.. Therefore, take a look on whether something like that hanepps somewhere in your code.

  • Comments are closed.