Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Get Your Ass to 1.9!

Get Your Ass to 1.9!

You already know that you _should_ be running Ruby 1.9, why aren't you? This is how New Relic upgraded our big-ass, five year old Rails 2.3 app to Ruby 1.9.

Nic Benders

March 07, 2013
Tweet

More Decks by Nic Benders

Other Decks in Technology

Transcript

  1. Ruby 1.9 has been out since 2009 (Ruby 2.0 is

    even out now) Ruby 1.8 will reach EOL in June REE has already reached EOL
  2. The New Relic App (as of mid-2012) 5 year old

    codebase 70,000 "Code LOC" and 59,000 "Test LOC" Rails 2.3.14 (started as Rails 1.2.3) REE-1.8.7-2010.02
  3. Putting it off Rearchitecting the app first Do it all

    in a big spike! Have a ruby_19 branch STUPID THINGS WE TRIED
  4. Do EVERYTHING on master Setup a CI job for it

    Start with your smaller apps THE BIG IDEA
  5. Be on latest Rails 2.3 or newer Use rbenv /

    rvm everywhere You already use Bundler, right? Decent test coverage (50% is ok) THE FOUNDATION
  6. Every commit is run both ways Slowly burn-down the failures

    (This took us several months) THE GRIND
  7. platforms :ruby_19 do gem 'debugger' gem 'crypt19' end platforms :ruby_18

    do gem 'ruby-debug' gem 'utility_belt' gem 'fastercsv' gem 'crypt', '1.1.4', :require => nil end
  8. # Rails 2.3 did not get along with Ruby 1.9.3

    until we did this # See - http://bit.ly/WPAj7a if ::RUBY_VERSION.split('.')[0,3] == ['1','9','3'] MissingSourceFile::REGEXPS.push( [/^cannot load such file -- (.+)$/i, 1] ) end
  9. # Prevent accidentally calling #[] on a number [Fixnum, Bignum].each

    do |k| k.class_eval do def [](*args) raise NoMethodError, "Calling #[] on numbers is wrong." end end end
  10. # Use to_sym to ensure that you always have a

    # symbol in 1.8 or 1.9 instance_methods.map(&:to_sym).include?(:connection)
  11. require "csv" # In Ruby 1.8, the library is called

    FasterCSV, # in 1.9 it's just CSV. So use some constant tricks # to make sure it's always "CSV" for us if CSV.const_defined? :Reader # Ruby 1.8 compatible require 'fastercsv' Object.send(:remove_const, :CSV) CSV = FasterCSV else # CSV is now FasterCSV in ruby 1.9 end
  12. --- a/script/server +++ b/script/server @@ -1,3 +1,3 @@ #!/usr/bin/env ruby

    -require File.dirname(__FILE__) + '/../config/boot' +require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
  13. Rotate the knowledge Make it easy to test both locally

    Background jobs were un-tested THINGS TO DO BETTER
  14. Changing the wheels on the bus at 80 mph: upgrading

    to Rails 3 on an active master branch Andrew Bloomgarden and Julian Giuca