Skip to content

Instantly share code, notes, and snippets.

View pglombardo's full-sized avatar
🕶️

Peter Giacomo Lombardo pglombardo

🕶️
View GitHub Profile
@pglombardo
pglombardo / error.txt
Created March 31, 2015 15:57
Refinery Error
NameError in Refinery::Admin::CoreController#index
uninitialized constant Refinery::I18n::Engine::Globalize
Rails.root: /home/pglombardo/Projects/ruby-test-stacks/refinethis2
Application Trace | Framework Trace | Full Trace
refinerycms-i18n (3.0.1) lib/refinery/i18n/engine.rb:63:in `globalize!'
activesupport (4.1.9) lib/active_support/callbacks.rb:424:in `block in make_lambda'
activesupport (4.1.9) lib/active_support/callbacks.rb:160:in `call'
activesupport (4.1.9) lib/active_support/callbacks.rb:160:in `block in halting'
@pglombardo
pglombardo / puma.rb
Last active August 29, 2015 14:16
TraceView, Heroku & the Puma Webserver
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
@pglombardo
pglombardo / sr_read_and_print_loop.rb
Created January 6, 2015 18:14
Query and Dump SampleRate/Source values every second
#!/usr/bin/env ruby
Bundler.require(:default)
Oboe::Config[:tracing_mode] = :always
while true do
Oboe.sample?(:layer => 'rack')
puts "PID - SampleRate/Source: #{Process.pid} - #{Oboe.sample_rate}/#{Oboe.sample_source}"
sleep 1
@pglombardo
pglombardo / measure.md
Last active February 23, 2024 00:02
Comprehensive Guide to Ruby Performance Benchmarking

GC.disable

Wall Clock Time versus CPU Time

An important difference to note is the how time is reported by various measurement methods. Wall clock time is the actual time passed in terms of human perception whereas CPU time is the time spent processing the work. CPU time doesn't include any delays waiting on resources to free up such as thread interrupts or garbage collection.

The Work to Measure

To keep things simple, we'll create a Ruby Proc and just repeatedly call that Proc for each of the measurement methods below.

@pglombardo
pglombardo / report.rb
Created July 30, 2014 20:35
TraceView Backtrace Reporter
def report_backtrace
kvs = { :Backtrace => Oboe::API.backtrace }
if Oboe.tracing?
Oboe::API.log(nil, 'info', kvs)
else
Oboe::API.start_trace('manual', { "Force" => true }) do
Oboe::API.log(nil, 'info', kvs)
end
end
@pglombardo
pglombardo / async.rb
Created July 2, 2014 21:29
Async Test Instrumentation
EventMachine::HttpConnection.class_eval do
def setup_request_with_oboe(*args, &block)
c = nil
::Oboe::API.log_entry('em-http-request', { uri: @uri, start: 'start' })
c = setup_request_without_oboe(*args, &block)
c.req.headers["X-Trace"] = Oboe::Context.toString()
::Oboe::API.log(nil, 'info', { uri: @uri })
@pglombardo
pglombardo / async.md
Last active August 29, 2015 14:03
TraceView Async Event Logging

HOW-TO: ASYNCHRONOUS AND PARALLEL WORKFLOWS

Most web application requests follow a simple path through the application, regardless of whether it is blocking or evented, where the critical path of the request is the only work being done. However, some web applications make use of threads, eventlets, or queues to process work in parallel or out of the critical path.

In order to analyze traces with asynchronous and parallel workflows correctly, small annotations must be added to the trace’s events. They boil down to adding the key Async = True on “asynchronous” layers. Here’s how to handle two common scenarios:

@pglombardo
pglombardo / code.rb
Created June 30, 2014 21:39
Mongo Find - with and without result reference
@session = Moped::Session.new([ "127.0.0.1:27017" ])
@session.use :moped_test
@users = @session[:users]
Oboe::API.start_trace('just_mongo_find', nil, { :Force => true }) do
@users.find
end
Oboe::API.start_trace('mongo_find_and_count', nil, { :Force => true }) do
@users.find.count
@pglombardo
pglombardo / irc2hipchat.md
Last active August 29, 2015 14:03
IRC2HipChat - Log IRC channel messages to a HipChat room

IRC2HipChat is a short Ruby script that uses Cinch to monitor IRC and re-post messages to a dedicated HipChat room using the HipChat API gem.

  on :channel do |m|
    msg = "<em>#{m.user.nick}</em>: #{m.message}"
    $hipchat.send('irc2hipchat', msg, { :notify => true, :message_format => 'html' })
  end
@pglombardo
pglombardo / config.ru
Created June 10, 2014 16:50
Dashing with TraceView - The Rackup File
require 'dashing'
require 'oboe'
Oboe::Config[:tracing_mode] = 'always'
Oboe::Config[:sample_rate] = 1e6
Oboe::Config[:verbose] = true
configure do
set :auth_token, 'YOUR_AUTH_TOKEN'