{"id":160701,"date":"2012-11-29T12:25:04","date_gmt":"2012-11-29T08:25:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=160701"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=160701","title":{"rendered":"<span class=\"post_title\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 ActiveSupport::Notifications \u0438 \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b?<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<code>ActiveSupport::Notifications<\/code> \u2013 \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432 \u0440\u0435\u043b\u044c\u0441\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 Rails \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0441\u043b\u0430\u043d\u044b. \u042d\u0442\u043e \u0447\u0435\u043c-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <code>ActiveSupport::Callbacks<\/code>, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 <code>'render'<\/code>:<\/p>\n<pre><code class=\"ruby\">ActiveSupport::Notifications.subscribe(&quot;render&quot;) do |*args|   # \u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f render end <\/code><\/pre>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043c\u0435\u043d\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0442\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u0442\u0435\u0441\u044c \u043d\u0430 \u0432\u0441\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434 <code>subscribe<\/code>. \u041c\u0435\u0442\u043e\u0434 <code>subscribe<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430, \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0438\u0441\u043a\u0438 \u043e\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>ActiveSupport::Notifications.publish<\/code>:<\/p>\n<pre><code class=\"ruby\">ActiveSupport::Notifications.publish('render', 'arg1', 'arg2') <\/code><\/pre>\n<p>  \u0412 \u0431\u043b\u043e\u043a <code>subscribe<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b <code>'render'<\/code>, <code>'arg1'<\/code> \u0438 <code>'arg2'<\/code>.<\/p>\n<p>  \u042f \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0432 Rails \u043a\u043e\u0434\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u0446\u0438\u0430\u043d\u0430\u043b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u041d\u043e \u0432 <code>ActiveSupport::Notifications<\/code> \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>instrument<\/code>. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u043b\u043e\u043a \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043a\u0430\u043c\u0438 \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0445\u044d\u0448 \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. Rails \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u0430 \u043e\u043f\u043e\u0441\u0440\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e, \u0438 \u043c\u0435\u0442\u043e\u0434\u044b <code>subscribe<\/code> \u0438 <code>publish<\/code>, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0445 \u043b\u043e\u0433\u043e\u0432 \u0432 \u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u0441\u043a\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 (\u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435 \u0436\u0435 \u201c\u0438\u0437\u043c\u0435\u0440\u0438\u0442\u0435\u043b\u0438\u201d, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0432 \u043b\u043e\u0433)<\/p>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445 \u0436\u0435 \u0446\u0435\u043b\u0435\u0439 \u044d\u0442\u0438 \u201c\u0438\u0437\u043c\u0435\u0440\u0438\u0442\u0435\u043b\u0438\u201d \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043b\u043e\u0433. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"ruby\">def do_something   # \u0422\u0443\u0442 \u043d\u0430\u0448\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f end <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u0431\u043b\u043e\u043a <code>ActiveSupport::Notifications.instrument<\/code><\/p>\n<pre><code class=\"ruby\">def do_something   ActiveSupport::Notifications.instrument('benchmark.do_something', desc: 'Some description') do     # \u0422\u0443\u0442 \u043d\u0430\u0448\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f   end end <\/code><\/pre>\n<p>  \u0412 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u0435\u0441\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>config\/initializers\/benchmarking.rb<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 <code>'benchmark.'<\/code>.<\/p>\n<pre><code class=\"ruby\">logger = Logger.new(File.join(Rails.root, 'log', &quot;benchmarks.log&quot;)) ActiveSupport::Notifications.subscribe(%r\/benchmark\\.*\/) do |name, start, ending, transaction_id, payload|   method = name.split(?.).last   duration = (1000.0 * (ending - start))   message = if payload[:exception].present?     payload[:exception].join(' ')   else     payload[:desc].to_s   end   logger.info(&quot;Benchmark:%s: %.0fms - %s&quot; % method, duration, message) end <\/code><\/pre>\n<p>  \u0412 \u0431\u043b\u043e\u043a \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435: <code>name, start, ending, transaction_id, payload<\/code>.<\/p>\n<ul>\n<li><code>name<\/code> \u2013 \u0438\u043c\u044f \u043f\u043e\u0439\u043c\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f<\/li>\n<li><code>start<\/code> \u2013 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430<\/li>\n<li><code>ending<\/code> \u2013 \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043d\u0446\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430<\/li>\n<li><code>transaction_id<\/code> \u2013 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 id, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0434\u0430<\/li>\n<li><code>payload<\/code> \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u201c\u0438\u0437\u043c\u0435\u0440\u0438\u0442\u0435\u043b\u044c\u201d<\/li>\n<\/ul>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043b\u043e\u0433. \u041f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0432 <code>payload[:exception]<\/code> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u043c\u0430\u0441\u0438\u0432 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u042d\u0442\u043e \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u0447\u0435\u0441\u0442\u044c.<\/p>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u043e\u043b\u044c <code>ActiveSupport::Notifications<\/code> \u0432 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 Rails \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 <code>ActiveSupport::LogSubscriber<\/code>, <code>ActiveRecord::LogSubscriber<\/code>, <code>ActionController::LogSubscriber<\/code> \u0438 <code>ActionMailer::LogSubscriber<\/code>.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u043b\u043e\u043a \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0435\u043c\u0443.<\/p>\n<pre><code class=\"ruby\">callback = lambda do|*args|   # \u042d\u0442\u043e \u0431\u043b\u043e\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0441\u044b\u043b\u043a\u0438    # \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f &quot;event.name&quot; end  ActiveSupport::Notifications.subscribed(callback, &quot;event.name&quot;) do   # \u0411\u043b\u043e\u043a \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430 end <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0438\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 <code>unsubscribe<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0432 \u043d\u0435\u0433\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430.<\/p>\n<pre><code class=\"ruby\">ActiveSupport::Notifications.unsubscribe(subscriber) <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0441\u043a\u0440\u044b\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>ActiveSupport::Notifications::Fanout<\/code>, \u0442\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 <code>ActiveSupport::Notifications::Instrumenter<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>instrument<\/code><\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043c\u043e\u043d\u043a\u0438\u043f\u0430\u0442\u0447 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0442\u0430\u0439\u043c\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 <code>ActiveSupport::Notifications<\/code>:<\/p>\n<pre><code class=\"ruby\">class Module   def benchmark_it *names     options, names = benchmark_options_and_names(*names)     names.each do |name|       target, punctuation = name.to_s.sub(\/([?!=])$\/, ''), $1       define_method &quot;#{target}_with_benchmark#{punctuation}&quot; do |*args|         ActiveSupport::Notifications.instrument(&quot;benchmark.#{self.name}.#{name}&quot;, options) do           send(&quot;#{target}_without_benchmark#{punctuation}&quot;, *args)         end       end       alias_method_chain name, :benchmark     end   end    protected   def benchmark_options_and_names *args     options = args.last.is_a?(Hash) ? args.pop : {}     [{desc: ''}.merge(options), args]   end end  ActiveSupport::Notifications.subscribe(%r\/benchmark\\.*\/) do |name, start, ending, transaction_id, payload|   _, classname, method = name.split(?.)   duration = (1000.0 * (ending - start))   message = if payload[:exception].present?     payload[:exception].join(' ')   else     payload[:desc].to_s   end   Rails.logger.info(&quot;Benchmark: %s.%s: %.0fms - %s&quot; % classname, method, duration, message) end <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\">class MyClass   def my_method     # \u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0443\u0442 \u0447\u0435\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c   end      # \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434   benchmark_it :my_method, desc: '\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043b\u043e\u0433\u0433\u0435\u0440\u0430' end <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e? \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0435\u0445 \u0436\u0435 Rails \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0412\u0430\u0448 \u043a\u043e\u0434 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0430\u0431\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043b\u0430\u0434\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u0438\u0445 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044f \u043c\u043e\u0433\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u044e ORM \u0438\u043b\u0438 \u0435\u0449\u0435 \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 <code>MyORM<\/code>, \u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 <code>MyORM::LogSubscriber<\/code> \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 <code>ActiveSupport::LogSubscriber<\/code>. \u0412\u0435\u0441\u0442\u044c \u043a\u043e\u0434, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u043e\u0432 \u043d\u0435 \u0440\u0430\u0437\u043c\u0430\u0437\u0430\u043d \u043f\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041d\u0443, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u0442\u0447\u0438\u043a\u0438 \u043f\u043e \u0432\u0441\u0435\u0439 \u0431\u0438\u0431\u043b\u0435\u043e\u0442\u0435\u043a\u0435. \u041a\u0441\u0442\u0430\u0442\u0438, \u044d\u0442\u0438 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0434\u0430\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0435\u0449\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043c\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0437\u0430\u0432\u044f\u0437\u0430\u043d \u043d\u0430 Rails, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439, Rails \u0442\u043e\u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u043c\u043e\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u043d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043c\u043e\u0439 \u0433\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043a \u043e\u0431\u0449\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0449\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0442\u043e \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b.    \t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/160701\/\"> http:\/\/habrahabr.ru\/post\/160701\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<code>ActiveSupport::Notifications<\/code> \u2013 \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0432 \u0440\u0435\u043b\u044c\u0441\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 Rails \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0441\u043b\u0430\u043d\u044b. \u042d\u0442\u043e \u0447\u0435\u043c-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 <code>ActiveSupport::Callbacks<\/code>, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-160701","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/160701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=160701"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/160701\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=160701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=160701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=160701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}