$30 off During Our Annual Pro Sale. View Details »

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.

Matt Sanders

April 25, 2012
Tweet

Other Decks in Programming

Transcript

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

    View Slide

  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

    View Slide

  3. The Basics of
    AS::Noti cations
    Wednesday, April 25, 12

    View Slide

  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

    View Slide

  5. “What gets measured
    gets managed”
    - Peter Drucker
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  7. What Happened?
    Wednesday, April 25, 12

    View Slide

  8. How It Works
    • #subscribe - ask to receive
    instrument data
    • #instrument - signal event or
    track data about operation
    (duration / exceptions)
    Wednesday, April 25, 12

    View Slide

  9. #instrument
    Message Name
    (what you #subscribe to)
    Wednesday, April 25, 12

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  19. #instrument
    (Exceptions)
    Exception Type
    (as string, not class)
    Exception Message
    Wednesday, April 25, 12

    View Slide

  20. #subscribe
    Wednesday, April 25, 12

    View Slide

  21. #subscribe
    Wednesday, April 25, 12

    View Slide

  22. #subscribe
    Wednesday, April 25, 12

    View Slide

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

    View Slide

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

    View Slide

  25. Rails Instrumentation
    Wednesday, April 25, 12

    View Slide

  26. Rails Instrumentation
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  28. Performance Monitoring
    Wednesday, April 25, 12

    View Slide

  29. Rails Request Time
    Wednesday, April 25, 12

    View Slide

  30. Requests by Server
    Wednesday, April 25, 12

    View Slide

  31. Slow Requests
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  33. Error Count
    Wednesday, April 25, 12

    View Slide

  34. SQL Monitoring
    Wednesday, April 25, 12

    View Slide

  35. SQL Monitoring
    Wednesday, April 25, 12

    View Slide

  36. Queries by Instance
    Wednesday, April 25, 12

    View Slide

  37. Queries by Instance
    Wednesday, April 25, 12

    View Slide

  38. SELECTs by Model
    Wednesday, April 25, 12

    View Slide

  39. Wednesday, April 25, 12

    View Slide

  40. Wednesday, April 25, 12

    View Slide

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

    View Slide

  42. Custom Logging
    Wednesday, April 25, 12

    View Slide

  43. New Relic Tracking
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  45. Wednesday, April 25, 12

    View Slide

  46. KISS metrics
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  48. ...and more
    • Google Analytics events
    • Camp re / HipChat alerts
    • Schedule background jobs
    • Fire web hooks
    • etc
    Wednesday, April 25, 12

    View Slide

  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

    View Slide

  50. #unsubscribe
    Wednesday, April 25, 12

    View Slide

  51. Power Moves
    Wednesday, April 25, 12

    View Slide

  52. Wednesday, April 25, 12

    View Slide

  53. Conditional
    Instrumentation
    Wednesday, April 25, 12

    View Slide

  54. Wednesday, April 25, 12

    View Slide

  55. Instrument Per User
    Wednesday, April 25, 12

    View Slide

  56. Instrument Per User
    Wednesday, April 25, 12

    View Slide

  57. Wednesday, April 25, 12

    View Slide

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

    View Slide

  59. Simplifying Repetitive
    Instrumentation
    Wednesday, April 25, 12

    View Slide

  60. Just Forward It
    Wednesday, April 25, 12

    View Slide

  61. Simplifying Repetitive
    Subscribers
    Wednesday, April 25, 12

    View Slide

  62. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  63. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  64. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  65. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  66. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  67. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  68. LogSubscriber
    Wednesday, April 25, 12

    View Slide

  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

    View Slide

  70. Supporting #instrument
    in your Gems
    Wednesday, April 25, 12

    View Slide

  71. Faraday Instrumentation
    Custom
    Event Name
    Request Environment
    Passed as Payload
    Wednesday, April 25, 12

    View Slide

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

    View Slide

  73. Wednesday, April 25, 12

    View Slide

  74. Wednesday, April 25, 12

    View Slide

  75. Wednesday, April 25, 12

    View Slide

  76. Wednesday, April 25, 12

    View Slide

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

    View Slide

  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

    View Slide

  79. Questions?
    Matt Sanders
    twitter: @nextmat
    https://github.com/nextmat
    Wednesday, April 25, 12

    View Slide