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

Building a toolkit to detect performance regressions in Ruby on Rails core

Building a toolkit to detect performance regressions in Ruby on Rails core

My talk from RailsConf 2015.

Kir Shatrov

April 22, 2015
Tweet

More Decks by Kir Shatrov

Other Decks in Programming

Transcript

  1. before = GC.stat[:total_allocated_object] 10_000.times do { "key" => "value" }

    end after = GC.stat[:total_allocated_object] puts "allocated: #{after - before}"
  2. Setup Discourse Populate records Start Unicorn with RAILS_ENV=production Make requests

    with Apache Bench to the list of endpoints Print timings and memory usage
  3. Disable GC is necessary Warm up the code Make N

    iterations Calculate the mean timing and object allocations
  4. ActiveRecord::Base#create require_relative 'support/activerecord_base.rb' require_relative 'support/benchmark_rails.rb' fields = { name: "Kir",

    notes: "Note", created_at: Date.today } Benchmark.rails(1000, "activerecord/#{db_adapter}/create") do Exhibit.create(fields) end
  5. What do we want? See benchmark for every commit See

    benchmark for every PR Report to PR author (“activerecord became 2% slower”) See charts
  6. 3.6GHz Intel® Xeon® E3-1270 v3 Quad-Core 4 x 8GB Micron

    ECC Samsung SSD 845DC EVO - 240 GB Sponsored hardware
  7. Overview What is a performance regression How to track them

    How to solve them How to write benchmarks Automate tracking!
  8. How to track your app performance? Study how do Ruby

    objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly
  9. How to track your app performance? Study how do Ruby

    objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly
  10. Setup the app Populate records Start Unicorn with RAILS_ENV=production Make

    requests with Apache Bench to the list of endpoints Print timings and memory usage
  11. How to track your app performance? Study how do Ruby

    objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly