Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created February 9, 2012 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordansissel/1776939 to your computer and use it in GitHub Desktop.
Save jordansissel/1776939 to your computer and use it in GitHub Desktop.
require "rubygems"
require "ftw" # gem ftw
require "cabin" # gem cabin
require "logger" # ruby stdlib
if ARGV.length != 1
puts "Usage: #{$0} <url>"
exit 1
end
agent = FTW::Agent.new
url = ARGV[0]
logger = Cabin::Channel.new
logger.subscribe(Logger.new(STDOUT))
# Fetch the url 5 times, demonstrating connection reuse, etc.
5.times do
logger.time("Fetch #{url}") do
response = agent.get!(url)
bytes = 0
response.read_body do |chunk|
bytes += chunk.size
end
logger.info("Request complete", :body_length => bytes)
end
# Be nice, slow down.
sleep 1
end
% ruby example.ftw.rb https://github.com/
I, [2012-02-08T19:11:11.245426 #13699] INFO -- : Request complete {"body_length":19789}
I, [2012-02-08T19:11:11.245804 #13699] INFO -- : Fetch https://github.com/ {"duration":0.511655333}
I, [2012-02-08T19:11:12.353729 #13699] INFO -- : Request complete {"body_length":19789}
I, [2012-02-08T19:11:12.353921 #13699] INFO -- : Fetch https://github.com/ {"duration":0.105865132}
I, [2012-02-08T19:11:13.484178 #13699] INFO -- : Request complete {"body_length":19789}
I, [2012-02-08T19:11:13.484401 #13699] INFO -- : Fetch https://github.com/ {"duration":0.114285551}
I, [2012-02-08T19:11:14.598364 #13699] INFO -- : Request complete {"body_length":19789}
I, [2012-02-08T19:11:14.598599 #13699] INFO -- : Fetch https://github.com/ {"duration":0.111391323}
I, [2012-02-08T19:11:15.735007 #13699] INFO -- : Request complete {"body_length":19789}
I, [2012-02-08T19:11:15.735183 #13699] INFO -- : Fetch https://github.com/ {"duration":0.135280002}
% ruby example.ftw.rb https://encrypted.google.com/
I, [2012-02-08T19:11:23.703962 #13701] INFO -- : Request complete {"body_length":29396}
I, [2012-02-08T19:11:23.704318 #13701] INFO -- : Fetch https://encrypted.google.com/ {"duration":0.172261585}
I, [2012-02-08T19:11:24.781464 #13701] INFO -- : Request complete {"body_length":29396}
I, [2012-02-08T19:11:24.781754 #13701] INFO -- : Fetch https://encrypted.google.com/ {"duration":0.07671389}
I, [2012-02-08T19:11:25.884480 #13701] INFO -- : Request complete {"body_length":29384}
I, [2012-02-08T19:11:25.884911 #13701] INFO -- : Fetch https://encrypted.google.com/ {"duration":0.101778061}
I, [2012-02-08T19:11:26.976730 #13701] INFO -- : Request complete {"body_length":29408}
I, [2012-02-08T19:11:26.976925 #13701] INFO -- : Fetch https://encrypted.google.com/ {"duration":0.091585654}
I, [2012-02-08T19:11:28.060994 #13701] INFO -- : Request complete {"body_length":29396}
I, [2012-02-08T19:11:28.061228 #13701] INFO -- : Fetch https://encrypted.google.com/ {"duration":0.083539673}
% ruby example.ftw.rb http://twitter.com/
I, [2012-02-08T19:11:52.669915 #13703] INFO -- : Request complete {"body_length":40646}
I, [2012-02-08T19:11:52.670443 #13703] INFO -- : Fetch http://twitter.com/ {"duration":0.274139608}
I, [2012-02-08T19:11:53.790623 #13703] INFO -- : Request complete {"body_length":41297}
I, [2012-02-08T19:11:53.790987 #13703] INFO -- : Fetch http://twitter.com/ {"duration":0.11978818}
I, [2012-02-08T19:11:54.927929 #13703] INFO -- : Request complete {"body_length":40644}
I, [2012-02-08T19:11:54.928142 #13703] INFO -- : Fetch http://twitter.com/ {"duration":0.136395039}
I, [2012-02-08T19:11:56.074849 #13703] INFO -- : Request complete {"body_length":40644}
I, [2012-02-08T19:11:56.075083 #13703] INFO -- : Fetch http://twitter.com/ {"duration":0.145058952}
I, [2012-02-08T19:11:57.207060 #13703] INFO -- : Request complete {"body_length":40636}
I, [2012-02-08T19:11:57.207253 #13703] INFO -- : Fetch http://twitter.com/ {"duration":0.13044204}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment