Created
December 12, 2012 13:06
-
-
Save djo/4267589 to your computer and use it in GitHub Desktop.
Test script to profile requests with GC options in case you have only access into the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test script to profile requests with GC options in case you have only access into the console. | |
# | |
# Invoke the script in the staging/production console: | |
# | |
# RAILS_ENV=production rails console | |
# [1] pry(main)> load '/path/to/the-file/requests.rb' | |
# | |
# You will see benchmark results per link for analyzing. | |
# | |
# You should run it before and after changing GC options for comparison. | |
# For example you can start from these options for REE: | |
# | |
# RUBY_HEAP_MIN_SLOTS=600000 | |
# RUBY_GC_MALLOC_LIMIT=59000000 | |
# RUBY_HEAP_FREE_MIN=100000 | |
# | |
# These options should be set up as environment variables before you run the console. | |
require 'benchmark' | |
# Test links | |
links = [ | |
'/first-page', | |
'/second-page', | |
'/third-page' | |
] | |
# Turn off logs | |
ActiveRecord::Base.logger = ::Logger.new('/dev/null') | |
ActionController::Base.logger = ::Logger.new('/dev/null') | |
# Test provided links | |
links.each do |link| | |
status = app.get(link) | |
unless ([200, 201, 202].include? status) | |
raise "Some errors on the provided link '#{link}': \n\n#{app.body}" | |
end | |
end | |
# Run the benchmark | |
n = 10 | |
results = Benchmark.bm(50) do |x| | |
links.each do |link| | |
label = "#{link}:".last(40) | |
x.report(label) do | |
n.times { app.get(link) } | |
end | |
end | |
end | |
p results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment