Skip to content

Instantly share code, notes, and snippets.

@ShimShtein
Last active December 3, 2018 14:41
Show Gist options
  • Save ShimShtein/7761d9f2f2b1d38f76ca40e61f7197f6 to your computer and use it in GitHub Desktop.
Save ShimShtein/7761d9f2f2b1d38f76ca40e61f7197f6 to your computer and use it in GitHub Desktop.
Foreman performance analysis deep dive
  1. rack-mini-profiler: Swiss-army knife profiler for rails apps
  2. flamegraph: Nice and useful timeline visualizer for debugging long methods.
  3. memory_profiler: Easy to use memory profiler for memory consuming methods.
  4. heapy: Memory dump analyzer for advanced memory analysis.
  5. foreman-tracer: great tool for unintrusive tracing by lzap.
# SQL Logger:
ActiveRecord::Base.logger = Logger.new(STDOUT)
# REST Logger:
require 'rest_client'
RestClient.log =
Object.new.tap do |proxy|
def proxy.<<(message)
Rails.logger.info message
end
end
gem 'rack-mini-profiler'
# # For memory profiling (requires Ruby MRI 2.1+)
gem 'memory_profiler'
#
# For call-stack profiling flamegraphs (requires Ruby MRI 2.0.0+)
gem 'flamegraph'
gem 'stackprof' # For Ruby MRI 2.1+
gem 'fast_stack' # For Ruby MRI 2.0
yum install gcc
yum install rh-ruby22-ruby-devel
scl enable tfm "gem install stackprof flamegraph memory_profiler rack-mini-profiler"
# It's ugly, but it works:
cat <<EOF > /usr/share/foreman/config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
# add requires for rack-mini-profiler and enable it:
require 'memory_profiler'
require 'stackprof'
require 'flamegraph'
require 'rack-mini-profiler'
use Rack::MiniProfiler
# /add
# apply a prefix to the application, if one is defined
# e.g. http://some.server.com/prefix where '/prefix' is defined by env variable
map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
run Foreman::Application
end
EOF
systemctl restart httpd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment