get your ass to 1.9
DESCRIPTION
This is the story of how New Relic upgraded our five year old, 125,000+ line Rails app from Ruby 1.8.7 to 1.9.3 without stopping the rest of our business. There are a lot of apps still out there running 1.8. All the easy ones are upgraded already, this is how to handle the rest of them.TRANSCRIPT
![Page 1: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/1.jpg)
GET YOUR ASS TO 1.9!
@nicbenders @ralphbod
http://nicbenders.com/ruby-19/
![Page 2: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/2.jpg)
GET YOUR ASS TO 1.9!
@nicbenders @ralphbod
http://nicbenders.com/ruby-19/
![Page 3: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/3.jpg)
![Page 4: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/4.jpg)
![Page 5: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/5.jpg)
![Page 6: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/6.jpg)
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
![Page 7: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/7.jpg)
0
3750
7500
11250
15000
1.8.6 1.8.7 1.9.2 1.9.3 2.0.0
![Page 8: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/8.jpg)
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
![Page 9: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/9.jpg)
Putting it off
Rearchitecting the app first
Do it all in a big spike!
Have a ruby_19 branch
STUPID THINGS WE TRIED
![Page 10: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/10.jpg)
Do EVERYTHING on master
Setup a CI job for it
Start with your smaller apps
THE BIG IDEA
![Page 11: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/11.jpg)
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
![Page 12: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/12.jpg)
Getting the test suite to run
Upgrade obsolete 3rd party libs
THE HARD PART
![Page 13: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/13.jpg)
Every commit is run both ways
Slowly burn-down the failures
(This took us several months)
THE GRIND
![Page 14: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/14.jpg)
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 => nilend
![Page 15: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/15.jpg)
# Rails 2.3 did not get along with Ruby 1.9.3 until we did this# See - http://bit.ly/WPAj7aif ::RUBY_VERSION.split('.')[0,3] == ['1','9','3'] MissingSourceFile::REGEXPS.push( [/^cannot load such file -- (.+)$/i, 1] )end
![Page 16: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/16.jpg)
# 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 endend
![Page 17: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/17.jpg)
# Use to_sym to ensure that you always have a# symbol in 1.8 or 1.9instance_methods.map(&:to_sym).include?(:connection)
![Page 18: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/18.jpg)
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 usif CSV.const_defined? :Reader # Ruby 1.8 compatible require 'fastercsv' Object.send(:remove_const, :CSV) CSV = FasterCSVelse # CSV is now FasterCSV in ruby 1.9end
![Page 19: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/19.jpg)
--- 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'
![Page 20: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/20.jpg)
Mongrel
Ordered Hashes
Regex changes
Encodings
Enumerable String
Lambda Arity
![Page 21: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/21.jpg)
Local dev environment first
Then each "Staging" env
Practice the roll-back plan
STARTING THE DEPLOY
![Page 22: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/22.jpg)
Roll out servers one-by-one
Have extra capacity available
Be patient!
THE BIG DAY
![Page 23: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/23.jpg)
![Page 24: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/24.jpg)
Rotate the knowledge
Make it easy to test both locally
Background jobs were un-tested
THINGS TO DO BETTER
![Page 25: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/25.jpg)
Changing the wheels on the bus at 80 mph: upgrading to Rails 3 on an active master branch
Andrew Bloomgarden and Julian Giuca
![Page 26: Get your ass to 1.9](https://reader033.vdocument.in/reader033/viewer/2022060119/558d14f8d8b42a7f248b45aa/html5/thumbnails/26.jpg)
JOIN THE TEAMnewrelic.com/about/jobs