Instrumenting Ruby on Rails With Traceview

45
1 On Building : Instrumen1ng Ruby with TraceView in 10 minutes Peter Lombardo h$p:// blog.gameface.in h$p:// www.appneta.com /blog

description

Installation and setup of TraceView for your Ruby application is a simple two step process that can be done in 10 minutes or less. Traceview gives a unique in-depth view into requests even as they cross hosts and software stacks. I run it on Gameface and PasswordPusher - it’s an essential tool in identifying problem areas, application performance bottlenecks and simply poor performing code. (Read: ActionView) To learn more about TraceView, visit http://appneta.com/traceview or read the AppNeta blog at http://appneta.com/blog

Transcript of Instrumenting Ruby on Rails With Traceview

Page 1: Instrumenting Ruby on Rails With Traceview

   

1  

On  Building                :  Instrumen1ng  Ruby  with  TraceView  in  10  minutes  

   Peter  Lombardo  

h$p://blog.gameface.in   h$p://www.appneta.com/blog  

Page 2: Instrumenting Ruby on Rails With Traceview

I’ve  been  a  Rubyist  and  Linux  addict  for  over  a  decade,  mainly  developing  in  Ruby  and  JavaScript  (as  well  as  PHP  and  Perl).  I’m  the  creator  of  numerous  soHware  tools  and  applicaIons,  most  recently  Password  Pusher,  a  Ruby  on  Rails  applicaIon  to  communicate  passwords  over  the  web  and  Gameface,  a  social  networking  plaLorm  for  gamers  using  Rails  3.      When  I’m  not  creaIng  my  own  applicaIons,  I  help  develop  and  maintain  the  infrastructure  at  OurStage  and  manage  the  Ruby  community  for  AppNeta.  

Peter  Lombardo  

Page 3: Instrumenting Ruby on Rails With Traceview

 “Gameface  was  created  to    

showcase  games,    the  people  who  play  them,  

and  the  characters  they  play”  

 

Page 4: Instrumenting Ruby on Rails With Traceview
Page 5: Instrumenting Ruby on Rails With Traceview

TraceView  by  AppNeta  gives  a  unique  in-­‐depth  view  into  requests  even  as  they  cross  hosts  and  soKware  stacks.    Installa1on  and  setup  of  TraceView  for  your  app  is  a  simple  two  step  process  that  can  be  done  in  10  minutes  or  less.    

h$p://www.appneta.com/traceview   h$p://www.appneta.com/  

Page 6: Instrumenting Ruby on Rails With Traceview

TraceView  provides  deep  performance  monitoring  of  web  apps.  

 It  gives  insight  into  your  web  app  

performance  such  as  this:          

Page 7: Instrumenting Ruby on Rails With Traceview
Page 8: Instrumenting Ruby on Rails With Traceview

…and  a  per  request  drill-­‐down  that  shows  you  the  niOy  griOy  detail  of  where  1me  is  

spent  in  individual  requests  

Page 9: Instrumenting Ruby on Rails With Traceview
Page 10: Instrumenting Ruby on Rails With Traceview
Page 11: Instrumenting Ruby on Rails With Traceview

and  even  end-­‐user  monitoring:      

Page 12: Instrumenting Ruby on Rails With Traceview
Page 13: Instrumenting Ruby on Rails With Traceview

I  run  it  on  Gameface  and  PasswordPusher  -­‐  it’s  essen1al  in  iden1fying  problem  

areas,  performance  boOlenecks  and  poor  performing  code.  (Read:  Ac1onView)        Disclaimer:  I  authored  the  Ruby  instrumenta6on  for  Traceview  so  I  may  be  a  bit  biased.  …but  with  good  reason!  

h$p://gameface.in   h$p://pwpush.com/  

Page 14: Instrumenting Ruby on Rails With Traceview

Installa1on    

Page 15: Instrumenting Ruby on Rails With Traceview

Installing  TraceView  consists  of  two  parts:      

1)  installing  the  system  daemon  on  your  host,  and    

2)  installing  the  Ruby  gem  in  your  applica1on  

h$p://www.appneta.com/apm-­‐datasheet  

Page 16: Instrumenting Ruby on Rails With Traceview

Why  a  system  daemon?      

TraceView  uses  a  system  daemon  to  collect  instrumenta6on  from  sources  beyond  applica6on  code  such  as  host  metrics,  

Apache  or  Resque.  

Page 17: Instrumenting Ruby on Rails With Traceview

The  system  daemon  is  installed  with  two  commands  that  can  be  pasted  into  your  shell.      An  account  specific  version  of  these  commands  is  available  in  your  TraceView  dashboard  once  you  create  an  account.  

   (Under  SeWngs;  App  Configura1on;  Trace  New  Hosts)    

Page 18: Instrumenting Ruby on Rails With Traceview
Page 19: Instrumenting Ruby on Rails With Traceview

And  the  gem  for  your  applica1on  Gemfile  available  on  RubyGems:  

 

h$ps://rubygems.org/gems/oboe  

gem 'oboe' !

Page 20: Instrumenting Ruby on Rails With Traceview

Setup    

Page 21: Instrumenting Ruby on Rails With Traceview

TraceView  func1ons  by  sampling  a  subset  of  all  requests  that  go  through  your  web  applica1on.      This  sample  rate  must  be  set  at  the  entry  point  of  requests  in  your  applica1on.    

Page 22: Instrumenting Ruby on Rails With Traceview

This  can  be  a  load  balancer,  Apache/nginx  or  Ruby  itself.      Successive  hosts  and  soKware  stacks  that  requests  pass  through  will  act  appropriately  according  to  upstream  seWngs.!

Page 23: Instrumenting Ruby on Rails With Traceview

Yes.      That  means  requests  can  be  traced  across  hosts,  so6ware  stacks,  even  track  internal  API  calls  via  HTTP/SOAP/REST  which  make  for  spectacular  applicaEon  insight.  

 …But  that’s  another  post  for  another  Eme.  

 

Page 24: Instrumenting Ruby on Rails With Traceview

For  this  walkthrough  we’re  going  to  assume  that  you’re  running  a  Ruby  on  Rails  applica1on  with  Unicorn,  Thin,  Puma  or  any  other  Rack  based  Ruby  webserver.  

 To  instead  configure  Apache/nginx  as  the  entry  point,  see  here.  

Page 25: Instrumenting Ruby on Rails With Traceview

This  can  be  a  load  balancer,  Apache/nginx  or  Ruby  itself.      Successive  hosts  and  soKware  stacks  that  requests  pass  through  will  act  appropriately  according  to  upstream  seWngs.!

Page 26: Instrumenting Ruby on Rails With Traceview

If  you  setup  Apache  or  nginx  as  your  entry  point  then  you  can  skip  this  part  enErely.    The                      gem  will  take  it’s  tracing  instrucEons  from  upstream  automaEcally.  

Oboe!

Page 27: Instrumenting Ruby on Rails With Traceview

When  the                    gem  is  installed  in  your  applica1on,  it  makes  available    !!which  is  a  nested  hash  of  configura1on  op1ons  that  affect  how  your  applica1on  is  instrumented.  

Oboe::Config !

Oboe!

Page 28: Instrumenting Ruby on Rails With Traceview

Luckily,  the  defaults  are  very  smart  and  only  a  couple  ini1al  values  need  to  be  configured.    The  two  required  values  are:    Oboe::Config[:tracing_mode] = 'always' !Oboe::config[:sample_rate] = 100000 # 10% of incoming requests !

Page 29: Instrumenting Ruby on Rails With Traceview

These  values  enable  tracing  (:tracing_mode)  and  sets  the  sample  rate  to  10%  (:sample_rate).    The  sample_rate  is  calculated  by  the  value  out  of  one  million.      e.g.  300000  would  equal  a  30%  sample  rate  meaning  3  out  of  10  requests  would  be  sampled.      (For  low  traffic  sites,  you  may  want  to  set  these  values  higher.)!

Page 30: Instrumenting Ruby on Rails With Traceview

These  values  are  usually  set  in  a  Rails  ini1alizer  for  Ruby  on  Rails.      See  the  OpEonal  Rails  IniEalizer  sec1on  on  this  page.      A  complete  list  of  all  configura1on  op1ons  for   is  here.!Oboe::Config !

Page 31: Instrumenting Ruby on Rails With Traceview

And  that’s  it.  Now  to  the  good  stuff…!

Page 32: Instrumenting Ruby on Rails With Traceview

GeWng  Performance  Data    

Page 33: Instrumenting Ruby on Rails With Traceview

If  you  want  to  test  that  the  oboe  gem  is  func1onal,  start-­‐up  a  Rails  console,  you  should  see  a  message  to  stdout  similar  to:  

 Tracelytics oboe gem 1.4.0.2 successfully loaded. !

Page 34: Instrumenting Ruby on Rails With Traceview

Note  that  on  hosts  that  don’t  have  the  system  daemon  installed,  the  oboe  gem  disables  itself  and  outputs  a  message  to  that  fact:      

 

Deploy/restart  your  applica1on  and  you  should  start  seeing  traces  show  up  in  your  TraceView  dashboard  aKer  a  couple  minutes.  

Unsupported Tracelytics environment (no libs). Going No-op. !

Page 35: Instrumenting Ruby on Rails With Traceview

Things  are  moving  fast  for  the  Ruby  language  instrumenta1on  in  TraceView.      We  support  tracing  of:          

Page 36: Instrumenting Ruby on Rails With Traceview

memcache-­‐client,  memcached,    dalli,  mongo,    

moped,  mongoid,  mongomapper,  cassandra,    

Ac1veRecord  (postgres,  mysql,  mysql2)      

 …plus  more.    

Page 37: Instrumenting Ruby on Rails With Traceview

Most  recently  we  added  support  for  Rack  and  Resque  tracing.    For  a  full-­‐list  of  supported  libraries,  see  this  ar1cle.!

Page 38: Instrumenting Ruby on Rails With Traceview

Extras:    Some  Random  Chart  Porn  

 

Page 39: Instrumenting Ruby on Rails With Traceview

A  screenshot  that  I  sent  to  Linode  when  performance  unexpectedly  dropped:    

Page 40: Instrumenting Ruby on Rails With Traceview
Page 41: Instrumenting Ruby on Rails With Traceview

Linode  migrated  my  VPS  to  a  lesser  u1lized  host  with  evident  results    

(Thanks  Linode):    

Page 42: Instrumenting Ruby on Rails With Traceview
Page 43: Instrumenting Ruby on Rails With Traceview

An  older  issue  that  Gameface  had  with  atrocious  rendering  1mes:    

Page 44: Instrumenting Ruby on Rails With Traceview
Page 45: Instrumenting Ruby on Rails With Traceview

If  you  haven’t  tried  out  TraceView  yet,  give  it  a  run.  

   You  won’t  be  disappointed.  

   

Note:  AppNeta  now  offers  free  tracing  for  single  projects.  Check  it  out  on  their  pricing  page.