SlideShare a Scribd company logo
Profiling and monitoring
        ruby/rails

        JÁN SUCHAL
         @JSUCHAL
Optimalization

 “If you can’t measure it, you can’t improve it.” – Lord Kelvin
 Environment
   development vs. production (hw, sw, load)
   data (synthetic vs. real)
 Bottlenecks
   10sec * 1 run vs. 0.5s * 100 runs
   run time * runs vs. development time
 Microbenchmarks
   waste of time vs. 20 * 1% = 20%
 “There are three kinds of lies: lies, damned lies, and statistics.” –
  Benjamin Disraeli
     single run vs. multiple runs
     average vs. standard deviance, percentiles
     cold vs. hot cache
Profiler - Example

# profiler/dates.rb

require 'date'

def create_days_after(date_str, n)
  after = Date.strptime(date_str) + n
  after.strftime("%Y-%m-%d")
end

1000.times do
  create_days_after("1982-10-27", 5)
end
Ruby Profiler

 $ gem install ruby-prof
 $ ruby-prof dates.rb
   How long does each method take?

 $ ruby-prof dates.rb –m 3
   Just methods above 3% time

  Thread ID: 7749480
  Total: 0.653076

  %self     total      self   wait   child    calls   name
  12.97      0.19      0.08   0.00    0.18     2000   String#scan
  11.57      0.08      0.08   0.00    0.00   205000   String#===
   6.87      0.18      0.04   0.00    0.14     1000   String#gsub
   6.28      0.05      0.04   0.00    0.01    14000   Hash#values_at
   4.08      0.03      0.03   0.00    0.00    80470   Hash#default
   3.21      0.03      0.02   0.00    0.01     3000   Date#emit
Ruby Profiler

Thread ID: 7749480
Total: 0.653076

%self     total      self    wait   child    calls   name
12.97      0.19      0.08    0.00    0.18     2000   String#scan
11.57      0.08      0.08    0.00    0.00   205000   String#===
 6.87      0.18      0.04    0.00    0.14     1000   String#gsub
 6.28      0.05      0.04    0.00    0.01    14000   Hash#values_at
 4.08      0.03      0.03    0.00    0.00    80470   Hash#default
 3.21      0.03      0.02    0.00    0.01     3000   Date#emit

 total – time in method and children calls
 self – time in method call
 wait – wait time
 child – time in child calls
 call – number of times method invoked
Ruby Profiler

 $ ruby-prof dates.rb -m 3 -p graph
   Which method calls what and how many times?

Thread ID: 15523700
Total Time: 0.675587048

%total    %self    total   self    wait   child           calls   Name
                   0.20    0.10    0.00   0.20        2000/2000   <Class::Date>#_strptime_i
30.28%   14.70%    0.20    0.10    0.00   0.20             2000   String#scan
                   0.04    0.04    0.00   0.00    110000/205000   String#===
                   0.02    0.01    0.00   0.01        3000/5000   Date::Format::Bag#method_...
                   0.02    0.00    0.00   0.01        2000/3005   Class#new
                   0.01    0.01    0.00   0.00        5000/5000   String#sub!
                   0.01    0.00    0.00   0.01        2000/2000   Range#===
                   0.00    0.00    0.00   0.00        3000/3000   String#to_i
                   0.00    0.00    0.00   0.00        2000/2000   <Class::Regexp>#quote
                   0.00    0.00    0.00   0.00        2000/2000   Regexp#===
                   0.00    0.00    0.00   0.00        1000/1000   <Class::Date>#num_pattern?
                   0.00    0.00    0.00   0.00        1000/2000   <Class::Date>#_strptime_i
Ruby Profiler

Thread ID: 15523700
Total Time: 0.675587048

%total    %self    total   self    wait   child           calls   Name
                   0.20    0.10    0.00   0.20        2000/2000   <Class::Date>#_strptime_i
30.28%   14.70%    0.20    0.10    0.00   0.20             2000   String#scan
                   0.04    0.04    0.00   0.00    110000/205000   String#===
                   0.02    0.01    0.00   0.01        3000/5000   Date::Format::Bag#method_..



 three parts
   parent calls
   method

   children calls

 calls – number of calls from method/total number of calls
Ruby Profiler

 $ ruby-prof dates.rb -p graph_html -m 3 > graph.html
 $ ruby-prof dates.rb -p graph_html -m 3 –s self > graph.html
Profiler - KCacheGrind

 $ ruby-prof dates.rb -p call_tree -m 3 > dates1.grind
 $ kcachegrind dates1.grind
benchmark-ips

 require   'benchmark/ips'
 require   'ostruct'
 require   'hashr'
 require   'hashugar'

 SMALL_HASH = {:a => 1, :b => 2}

 Benchmark.ips do |x|
   x.report 'OpenStruct create small hash and access once', 'OpenStruct.new(SMALL_HASH).item5'
   x.report 'Hashr create small hash and access once', 'Hashr.new(SMALL_HASH).item5'
   x.report 'Hashugar create small hash and access once', 'Hashugar.new(SMALL_HASH).item5‘
 end


OpenStruct create small hash and access once
  43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697)
Hashr create small hash and access once
  67408.9 (±5.0%) i/s - 339780 in 5.053728s (cycle=5663)
Hashugar create small hash and access once
 230217.9 (±4.2%) i/s - 1152670 in 5.015705s (cycle=15790)
Memory profiling

 Patched ruby
 $ rvm install 1.9.3 --patch railsexpress --name gc
 $ ruby-prof --mode=allocations dates.rb –m 3


%self      total      self   wait     child   calls   name
59.23    6004.00   6004.00   0.00      0.00    1000   <Class::Date>#strptime
 9.87    1000.00   1000.00   0.00      0.00    1000   Date#strftime
 9.87    9004.00   1000.00   0.00   8004.00    1000   Object#create_days_after
 9.87    1000.00   1000.00   0.00      0.00    1000   Date#+
 9.87   10004.00   1000.00   0.00   9004.00       1   Integer#times
Rails / NewRelic Developer mode

 gem 'newrelic_rpm‘
 http://localhost:3000/newrelic
 gem 'newrelic_rpm', git:
 'git://github.com/jsuchal/rpm.git',
 branch: 'feature-profile-sorting'
NewRelic Developer mode
Rails / NewRelic Developer mode
NewRelic Developer mode
NewRelic Developer mode Profiler
Custom Method Tracers

# initializers/elastic_search_traces.rb

require 'new_relic/agent/method_tracer‘

ElasticSearch.class_eval do
  include NewRelic::Agent::MethodTracer

  add_method_tracer :search, 'Custom/elasticsearch/search'
  add_method_tracer :index, 'Custom/elasticsearch/index'
end
NewRelic Production Monitoring

 Web Transactions – controller actions drilldown
 Transaction Traces – detailed slow requests
 Slow SQL – slow queries
 Background job monitoring
 Availabality monitoring
 Deployment tracking
 Scalability analysis
 ...
 Server monitoring (load, disks, …)
Profiling and monitoring ruby & rails applications
Profiling and monitoring ruby & rails applications
Profiling and monitoring ruby & rails applications
Profiling and monitoring ruby & rails applications
Error tracking

 ExceptionNotifier
 www.airbrake.io
Most common performance problems

 “1 + N query problem”
   joins FTW!

 Lack of proper indexing
 Unnecessary ActiveRecord loading
   e.g. count vs. size vs. length

 Default GC parameters
    37signals params
    RUBY_HEAP_MIN_SLOTS=600000 # This is 60(!) times larger than default
    RUBY_GC_MALLOC_LIMIT=59000000 # This is 7 times larger than default
    RUBY_HEAP_FREE_MIN=100000 # This is 24 times larger than default

 Unknown abstraction internals
   e.g. OpenStruct

More Related Content

What's hot (18)

PDF
7주 JavaScript 실습
지수 윤
 
PPTX
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
Matthew Tovbin
 
PDF
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
Databricks
 
PDF
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
PDF
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack
 
PDF
Teaching Your Machine To Find Fraudsters
Ian Barber
 
PDF
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios
 
PDF
Living with garbage
lucenerevolution
 
KEY
Building Better Applications with Data::Manager
Jay Shirley
 
PDF
Nodejs mongoose
Fin Chen
 
PPT
Php Mysql
Mudasir Syed
 
PDF
How to stand on the shoulders of giants
Ian Barber
 
PDF
node.js Module Development
Jay Harris
 
PDF
rsyslog v8: more than just syslog!
Yury Bushmelev
 
PPTX
19. CodeIgniter imagini in mysql
Razvan Raducanu, PhD
 
PPT
Mocking Dependencies in PHPUnit
mfrost503
 
KEY
(Parameterized) Roles
sartak
 
7주 JavaScript 실습
지수 윤
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
Matthew Tovbin
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
Databricks
 
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack
 
Teaching Your Machine To Find Fraudsters
Ian Barber
 
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
Nagios
 
Living with garbage
lucenerevolution
 
Building Better Applications with Data::Manager
Jay Shirley
 
Nodejs mongoose
Fin Chen
 
Php Mysql
Mudasir Syed
 
How to stand on the shoulders of giants
Ian Barber
 
node.js Module Development
Jay Harris
 
rsyslog v8: more than just syslog!
Yury Bushmelev
 
19. CodeIgniter imagini in mysql
Razvan Raducanu, PhD
 
Mocking Dependencies in PHPUnit
mfrost503
 
(Parameterized) Roles
sartak
 

Similar to Profiling and monitoring ruby & rails applications (20)

PDF
Rails Performance
Wen-Tien Chang
 
PDF
Profiling ruby
nasirj
 
PPTX
Ruby/rails performance and profiling
Danny Guinther
 
PDF
ZOMG WHY IS THIS CODE SO SLOW
Aaron Patterson
 
KEY
Ruby objects
Reuven Lerner
 
PDF
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Olga Lavrentieva
 
PDF
Профилирование и оптимизация производительности Ruby-кода
samsolutionsby
 
ODP
Ruby Basics by Rafiq
Rafiqdeen
 
ODP
Performance Optimization of Rails Applications
Serge Smetana
 
KEY
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Ruby Meditation
 
PPTX
Ruby object model
Chamnap Chhorn
 
PDF
Ruby training day1
Bindesh Vijayan
 
PDF
how to rate a Rails application
ehuard
 
PPTX
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
PDF
RubyMiniGuide-v1.0_0
tutorialsruby
 
PDF
RubyMiniGuide-v1.0_0
tutorialsruby
 
PDF
Why ruby
Kenneth Kalmer
 
PPTX
Introduction to Ruby’s Reflection API
Niranjan Sarade
 
KEY
UT on Rails3 2010- Week 2
Richard Schneeman
 
Rails Performance
Wen-Tien Chang
 
Profiling ruby
nasirj
 
Ruby/rails performance and profiling
Danny Guinther
 
ZOMG WHY IS THIS CODE SO SLOW
Aaron Patterson
 
Ruby objects
Reuven Lerner
 
Практический опыт профайлинга и оптимизации производительности Ruby-приложений
Olga Lavrentieva
 
Профилирование и оптимизация производительности Ruby-кода
samsolutionsby
 
Ruby Basics by Rafiq
Rafiqdeen
 
Performance Optimization of Rails Applications
Serge Smetana
 
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Ruby Meditation
 
Ruby object model
Chamnap Chhorn
 
Ruby training day1
Bindesh Vijayan
 
how to rate a Rails application
ehuard
 
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
RubyMiniGuide-v1.0_0
tutorialsruby
 
RubyMiniGuide-v1.0_0
tutorialsruby
 
Why ruby
Kenneth Kalmer
 
Introduction to Ruby’s Reflection API
Niranjan Sarade
 
UT on Rails3 2010- Week 2
Richard Schneeman
 
Ad

More from Jano Suchal (20)

PDF
Slovensko.Digital: Čo ďalej?
Jano Suchal
 
PDF
Datanest 3.0
Jano Suchal
 
PDF
Improving code quality
Jano Suchal
 
PDF
Beyond search queries
Jano Suchal
 
PDF
Rank all the things!
Jano Suchal
 
PDF
Rank all the (geo) things!
Jano Suchal
 
PDF
Ako si vybrať programovácí jazyk alebo framework?
Jano Suchal
 
PPTX
Bonetics: Mastering Puppet Workshop
Jano Suchal
 
PPTX
Peter Mihalik: Puppet
Jano Suchal
 
PDF
Tomáš Čorej: Configuration management & CFEngine3
Jano Suchal
 
PDF
Ako si vybrať programovací jazyk a framework?
Jano Suchal
 
PDF
SQL: Query optimization in practice
Jano Suchal
 
PDF
Garelic: Google Analytics as App Performance monitoring
Jano Suchal
 
PDF
Miroslav Šimulčík: Temporálne databázy
Jano Suchal
 
PDF
Vojtech Rinik: Internship v USA - moje skúsenosti
Jano Suchal
 
PDF
Aký programovací jazyk a framework si vybrať a prečo?
Jano Suchal
 
PDF
Čo po GAMČI?
Jano Suchal
 
PDF
Petr Joachim: Redis na Super.cz
Jano Suchal
 
PDF
Metaprogramovanie #1
Jano Suchal
 
PDF
PostgreSQL: Advanced features in practice
Jano Suchal
 
Slovensko.Digital: Čo ďalej?
Jano Suchal
 
Datanest 3.0
Jano Suchal
 
Improving code quality
Jano Suchal
 
Beyond search queries
Jano Suchal
 
Rank all the things!
Jano Suchal
 
Rank all the (geo) things!
Jano Suchal
 
Ako si vybrať programovácí jazyk alebo framework?
Jano Suchal
 
Bonetics: Mastering Puppet Workshop
Jano Suchal
 
Peter Mihalik: Puppet
Jano Suchal
 
Tomáš Čorej: Configuration management & CFEngine3
Jano Suchal
 
Ako si vybrať programovací jazyk a framework?
Jano Suchal
 
SQL: Query optimization in practice
Jano Suchal
 
Garelic: Google Analytics as App Performance monitoring
Jano Suchal
 
Miroslav Šimulčík: Temporálne databázy
Jano Suchal
 
Vojtech Rinik: Internship v USA - moje skúsenosti
Jano Suchal
 
Aký programovací jazyk a framework si vybrať a prečo?
Jano Suchal
 
Čo po GAMČI?
Jano Suchal
 
Petr Joachim: Redis na Super.cz
Jano Suchal
 
Metaprogramovanie #1
Jano Suchal
 
PostgreSQL: Advanced features in practice
Jano Suchal
 
Ad

Recently uploaded (20)

PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 

Profiling and monitoring ruby & rails applications

  • 1. Profiling and monitoring ruby/rails JÁN SUCHAL @JSUCHAL
  • 2. Optimalization  “If you can’t measure it, you can’t improve it.” – Lord Kelvin  Environment  development vs. production (hw, sw, load)  data (synthetic vs. real)  Bottlenecks  10sec * 1 run vs. 0.5s * 100 runs  run time * runs vs. development time  Microbenchmarks  waste of time vs. 20 * 1% = 20%  “There are three kinds of lies: lies, damned lies, and statistics.” – Benjamin Disraeli  single run vs. multiple runs  average vs. standard deviance, percentiles  cold vs. hot cache
  • 3. Profiler - Example # profiler/dates.rb require 'date' def create_days_after(date_str, n) after = Date.strptime(date_str) + n after.strftime("%Y-%m-%d") end 1000.times do create_days_after("1982-10-27", 5) end
  • 4. Ruby Profiler  $ gem install ruby-prof  $ ruby-prof dates.rb  How long does each method take?  $ ruby-prof dates.rb –m 3  Just methods above 3% time Thread ID: 7749480 Total: 0.653076 %self total self wait child calls name 12.97 0.19 0.08 0.00 0.18 2000 String#scan 11.57 0.08 0.08 0.00 0.00 205000 String#=== 6.87 0.18 0.04 0.00 0.14 1000 String#gsub 6.28 0.05 0.04 0.00 0.01 14000 Hash#values_at 4.08 0.03 0.03 0.00 0.00 80470 Hash#default 3.21 0.03 0.02 0.00 0.01 3000 Date#emit
  • 5. Ruby Profiler Thread ID: 7749480 Total: 0.653076 %self total self wait child calls name 12.97 0.19 0.08 0.00 0.18 2000 String#scan 11.57 0.08 0.08 0.00 0.00 205000 String#=== 6.87 0.18 0.04 0.00 0.14 1000 String#gsub 6.28 0.05 0.04 0.00 0.01 14000 Hash#values_at 4.08 0.03 0.03 0.00 0.00 80470 Hash#default 3.21 0.03 0.02 0.00 0.01 3000 Date#emit  total – time in method and children calls  self – time in method call  wait – wait time  child – time in child calls  call – number of times method invoked
  • 6. Ruby Profiler  $ ruby-prof dates.rb -m 3 -p graph  Which method calls what and how many times? Thread ID: 15523700 Total Time: 0.675587048 %total %self total self wait child calls Name 0.20 0.10 0.00 0.20 2000/2000 <Class::Date>#_strptime_i 30.28% 14.70% 0.20 0.10 0.00 0.20 2000 String#scan 0.04 0.04 0.00 0.00 110000/205000 String#=== 0.02 0.01 0.00 0.01 3000/5000 Date::Format::Bag#method_... 0.02 0.00 0.00 0.01 2000/3005 Class#new 0.01 0.01 0.00 0.00 5000/5000 String#sub! 0.01 0.00 0.00 0.01 2000/2000 Range#=== 0.00 0.00 0.00 0.00 3000/3000 String#to_i 0.00 0.00 0.00 0.00 2000/2000 <Class::Regexp>#quote 0.00 0.00 0.00 0.00 2000/2000 Regexp#=== 0.00 0.00 0.00 0.00 1000/1000 <Class::Date>#num_pattern? 0.00 0.00 0.00 0.00 1000/2000 <Class::Date>#_strptime_i
  • 7. Ruby Profiler Thread ID: 15523700 Total Time: 0.675587048 %total %self total self wait child calls Name 0.20 0.10 0.00 0.20 2000/2000 <Class::Date>#_strptime_i 30.28% 14.70% 0.20 0.10 0.00 0.20 2000 String#scan 0.04 0.04 0.00 0.00 110000/205000 String#=== 0.02 0.01 0.00 0.01 3000/5000 Date::Format::Bag#method_..  three parts  parent calls  method  children calls  calls – number of calls from method/total number of calls
  • 8. Ruby Profiler  $ ruby-prof dates.rb -p graph_html -m 3 > graph.html  $ ruby-prof dates.rb -p graph_html -m 3 –s self > graph.html
  • 9. Profiler - KCacheGrind  $ ruby-prof dates.rb -p call_tree -m 3 > dates1.grind  $ kcachegrind dates1.grind
  • 10. benchmark-ips require 'benchmark/ips' require 'ostruct' require 'hashr' require 'hashugar' SMALL_HASH = {:a => 1, :b => 2} Benchmark.ips do |x| x.report 'OpenStruct create small hash and access once', 'OpenStruct.new(SMALL_HASH).item5' x.report 'Hashr create small hash and access once', 'Hashr.new(SMALL_HASH).item5' x.report 'Hashugar create small hash and access once', 'Hashugar.new(SMALL_HASH).item5‘ end OpenStruct create small hash and access once 43858.0 (±5.5%) i/s - 221820 in 5.074250s (cycle=3697) Hashr create small hash and access once 67408.9 (±5.0%) i/s - 339780 in 5.053728s (cycle=5663) Hashugar create small hash and access once 230217.9 (±4.2%) i/s - 1152670 in 5.015705s (cycle=15790)
  • 11. Memory profiling  Patched ruby  $ rvm install 1.9.3 --patch railsexpress --name gc  $ ruby-prof --mode=allocations dates.rb –m 3 %self total self wait child calls name 59.23 6004.00 6004.00 0.00 0.00 1000 <Class::Date>#strptime 9.87 1000.00 1000.00 0.00 0.00 1000 Date#strftime 9.87 9004.00 1000.00 0.00 8004.00 1000 Object#create_days_after 9.87 1000.00 1000.00 0.00 0.00 1000 Date#+ 9.87 10004.00 1000.00 0.00 9004.00 1 Integer#times
  • 12. Rails / NewRelic Developer mode  gem 'newrelic_rpm‘  http://localhost:3000/newrelic  gem 'newrelic_rpm', git: 'git://github.com/jsuchal/rpm.git', branch: 'feature-profile-sorting'
  • 14. Rails / NewRelic Developer mode
  • 17. Custom Method Tracers # initializers/elastic_search_traces.rb require 'new_relic/agent/method_tracer‘ ElasticSearch.class_eval do include NewRelic::Agent::MethodTracer add_method_tracer :search, 'Custom/elasticsearch/search' add_method_tracer :index, 'Custom/elasticsearch/index' end
  • 18. NewRelic Production Monitoring  Web Transactions – controller actions drilldown  Transaction Traces – detailed slow requests  Slow SQL – slow queries  Background job monitoring  Availabality monitoring  Deployment tracking  Scalability analysis  ...  Server monitoring (load, disks, …)
  • 24. Most common performance problems  “1 + N query problem”  joins FTW!  Lack of proper indexing  Unnecessary ActiveRecord loading  e.g. count vs. size vs. length  Default GC parameters  37signals params  RUBY_HEAP_MIN_SLOTS=600000 # This is 60(!) times larger than default  RUBY_GC_MALLOC_LIMIT=59000000 # This is 7 times larger than default  RUBY_HEAP_FREE_MIN=100000 # This is 24 times larger than default  Unknown abstraction internals  e.g. OpenStruct