Digging Deep with ActiveSupport::Notifications

Digging Deep with ActiveSupport::Notifications

ActiveSupport::Notifications is a powerful, under-utilized library which makes it easy to instrument and monitor your code. Rails exposes a tons of performance information which is easy to access and you can create your own events with a single line of code. This talk explores the basics of ActiveSupport::Notifications and gets into powerful techniques you can use to super-charge your monitoring and instrumentation.

F4d4e7e12544f6e3c660481f3bcccb0f?s=128

Matt Sanders

April 25, 2012
Tweet

Transcript

  1. Digging Deep With ActiveSupport:: Noti cations Wednesday, April 25, 12

  2. Let’s Talk... • What is ActiveSupport::Noti cations? • Why you

    should care • How it works • What you can do with it Wednesday, April 25, 12
  3. The Basics of AS::Noti cations Wednesday, April 25, 12

  4. • AS::Noti cations provides a simple, exible messaging system for

    instrumenting • Lots of valuable data is already exposed by Rails’ built-in instrumentation • Provides an easy path for performance monitoring what you care about in your application • Log & track what matters to you! Why you should care Wednesday, April 25, 12
  5. “What gets measured gets managed” - Peter Drucker Wednesday, April

    25, 12
  6. production != development Wednesday, April 25, 12

  7. What Happened? Wednesday, April 25, 12

  8. How It Works • #subscribe - ask to receive instrument

    data • #instrument - signal event or track data about operation (duration / exceptions) Wednesday, April 25, 12
  9. #instrument Message Name (what you #subscribe to) Wednesday, April 25,

    12
  10. #instrument Message Name (what you #subscribe to) Extra Arguments (passed

    as payload to #subscribe) Wednesday, April 25, 12
  11. #instrument Message Name (what you #subscribe to) Extra Arguments (passed

    as payload to #subscribe) Wednesday, April 25, 12
  12. #instrument Message Name (what you #subscribe to) Extra Arguments (passed

    as payload to #subscribe) Time Objects Wednesday, April 25, 12
  13. #instrument Message Name (what you #subscribe to) Extra Arguments (passed

    as payload to #subscribe) Time Objects Unique Message ID Wednesday, April 25, 12
  14. #instrument Message Name (what you #subscribe to) Extra Arguments (passed

    as payload to #subscribe) Time Objects Payload Unique Message ID Wednesday, April 25, 12
  15. #instrument (Block Form) Wednesday, April 25, 12

  16. #instrument (Block Form) Wednesday, April 25, 12

  17. #instrument (Block Form) Duration (difference between these) Wednesday, April 25,

    12
  18. #instrument (Exceptions) Wednesday, April 25, 12

  19. #instrument (Exceptions) Exception Type (as string, not class) Exception Message

    Wednesday, April 25, 12
  20. #subscribe Wednesday, April 25, 12

  21. #subscribe Wednesday, April 25, 12

  22. #subscribe Wednesday, April 25, 12

  23. event#parent_of? Wednesday, April 25, 12

  24. #subscribe (using regular expressions) Wednesday, April 25, 12

  25. Rails Instrumentation Wednesday, April 25, 12

  26. Rails Instrumentation Wednesday, April 25, 12

  27. Rails Instrumentation Namespaced (right to left) Wednesday, April 25, 12

  28. Performance Monitoring Wednesday, April 25, 12

  29. Rails Request Time Wednesday, April 25, 12

  30. Requests by Server Wednesday, April 25, 12

  31. Slow Requests Wednesday, April 25, 12

  32. Slowest Req by Server Wednesday, April 25, 12

  33. Error Count Wednesday, April 25, 12

  34. SQL Monitoring Wednesday, April 25, 12

  35. SQL Monitoring Wednesday, April 25, 12

  36. Queries by Instance Wednesday, April 25, 12

  37. Queries by Instance Wednesday, April 25, 12

  38. SELECTs by Model Wednesday, April 25, 12

  39. Wednesday, April 25, 12

  40. Wednesday, April 25, 12

  41. What to do with instrumented data? Wednesday, April 25, 12

  42. Custom Logging Wednesday, April 25, 12

  43. New Relic Tracking Wednesday, April 25, 12

  44. Librato Metrics / StatsD Wednesday, April 25, 12

  45. Wednesday, April 25, 12

  46. KISS metrics Wednesday, April 25, 12

  47. Save Data For Later Wednesday, April 25, 12

  48. ...and more • Google Analytics events • Camp re /

    HipChat alerts • Schedule background jobs • Fire web hooks • etc Wednesday, April 25, 12
  49. Performance Notes • By default Rails calls subscribers in the

    thread where instrumentation took place • Consider backgrounding slow subscribers • Dispatcher can be replaced by your own queue system (set AS::Noti cations.noti er) Wednesday, April 25, 12
  50. #unsubscribe Wednesday, April 25, 12

  51. Power Moves Wednesday, April 25, 12

  52. Wednesday, April 25, 12

  53. Conditional Instrumentation Wednesday, April 25, 12

  54. Wednesday, April 25, 12

  55. Instrument Per User Wednesday, April 25, 12

  56. Instrument Per User Wednesday, April 25, 12

  57. Wednesday, April 25, 12

  58. Bot Up Your Life Wednesday, April 25, 12

  59. Simplifying Repetitive Instrumentation Wednesday, April 25, 12

  60. Just Forward It Wednesday, April 25, 12

  61. Simplifying Repetitive Subscribers Wednesday, April 25, 12

  62. LogSubscriber Wednesday, April 25, 12

  63. LogSubscriber Wednesday, April 25, 12

  64. LogSubscriber Wednesday, April 25, 12

  65. LogSubscriber Wednesday, April 25, 12

  66. LogSubscriber Wednesday, April 25, 12

  67. LogSubscriber Wednesday, April 25, 12

  68. LogSubscriber Wednesday, April 25, 12

  69. Use Outside of Rails • activesupport/noti cations can be required

    by itself, only needs securerandom to work • provides a good abstract interface for instrumentation • activesupport/log_subscriber is a separate library, can be required if needed Wednesday, April 25, 12
  70. Supporting #instrument in your Gems Wednesday, April 25, 12

  71. Faraday Instrumentation Custom Event Name Request Environment Passed as Payload

    Wednesday, April 25, 12
  72. Excon Instrumentation Allows Custom Instrumentor Custom Event Prefix Wednesday, April

    25, 12
  73. Wednesday, April 25, 12

  74. Wednesday, April 25, 12

  75. Wednesday, April 25, 12

  76. Wednesday, April 25, 12

  77. Discuss Conventions for AS::Noti cations in Your Team Wednesday, April

    25, 12
  78. In closing... • AS::Noti cations provides a simple message-based system

    for instrumentation • Use what Rails gives you, create what it doesn’t • Track what you want, track what matters to you! Wednesday, April 25, 12
  79. Questions? Matt Sanders twitter: @nextmat https://github.com/nextmat Wednesday, April 25, 12