activesupport::notifications inside out

16
ActiveSupport::Notifications Rails instrumentation inside out

Upload: frank-duan

Post on 14-Aug-2015

20 views

Category:

Software


0 download

TRANSCRIPT

ActiveSupport::Notifications

Rails instrumentation inside out

Context

★ Runtime data collection management★ Introduce Rails instrumentation★ Instrumentation in practice★ AS::Notification implementation★ Maximise instrumentation power

Runtime data collection management

Problems

★ Logging, profiling modules etc tightly coupled with functional modules

★ Modules mixed together (SRP violation)★ Different types of runtime data require

different handlers

Instrumentation to rescue

★ Data logging★ Event tracking★ Performance tracking★ Debugging and exception handling★ Profiling

Introduce Rails instrumentation

★ Provide and used by Rails★ Hook with Rails events or BYO★ Pub/ Sub pattern★ Highly customisable modules★ Thread safe

How Rails instrument - ActiveRecord

How Rails instrument - ActionView

Instrumentation in practice

Instrumentation in practice (cont)

Instrumentation in practice (cont)

Instrumentation in practice (cont)

AS::Notification implementation

ActiveSupport::PerThreadRegistry

Namesapced global varibles per thread

Maximise instrumentation power

★ Logging★ New Relic★ Email notification★ Event tracking - SiteCatalyst★ Stats collection - statsD★ Trigger Background jobs★ Web hooks to trigger other web services

Maximise instrumentation power

★ Independent from Rails, plug in to any Ruby projects

★ Good Abstraction○ replace notifier (Fanout) with your own queue○ pass in your own listeners to customise start/

publish/ finish hooks, instead of plain blocks★ Send slow subscriber works to background

jobs or message queues