Today I learned

Make Rails (and other dev servers) use less CPU

Is Rails eating your CPU in development? Try lowering its priority using renice(1), a standard BSD utility that should be available in OS X and most Linux distributions. Here's a shell script that will automatically reset the priority to +15 to common development processes:
#!/usr/bin/env sh
sudo renice +15 -p $(ps ax | grep -E 'ruby|node|watchman|postgres' | grep -v grep | awk '{print $1}' | tr '\n' ' ')

Save this as renice-dev into one of your bin paths, and give it a chmod +x renice-dev. You can type renice-dev after you start your development processes to "renice" them.

What is +15?

This is the priority to be assigned to matching processes. The lowest priority is +19 (only run when nothing else is running), the default is 0, and the highest is -20 (makes things go very fast).


You have just read Make Rails (and other dev servers) use less CPU, written on July 12, 2017. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles