Skip to content

Instantly share code, notes, and snippets.

@haifeng
Created April 3, 2013 14:10
Show Gist options
  • Save haifeng/5301538 to your computer and use it in GitHub Desktop.
Save haifeng/5301538 to your computer and use it in GitHub Desktop.
current benchmark for http
require 'jruby'
require 'http-request'
# require 'http'
require 'benchmark'
require 'http_client'
# require './async-http-client-1.7.12.jar'
# require './slf4j-log4j12-1.7.5.jar'
# require './async-http-client-1.6.1.jar'
# module Hclient
# include_package "org.slf4j"
# include_package "com.ning.http.client"
# java_import "org.slf4j.Logger"
# # java_import "org.slf4j.LoggerFactory"
# # java_import "com.ning.http.client.AsyncHttpClient"
# def self.run
# # builder = AsyncHttpClientConfig::Builder.new
# # builder.setCompressionEnabled(true)
# # .setAllowPoolingConnection(true)
# # .build
# aa = AsyncHttpClient.new
# # client = AsyncHttpClient.new(builder.build)
# # response = client.prepareGet("https://github.com").execute().get()
# # p response
# end
# end
# Hclient.run
# exit
# "http://jacksonphillipsinc.com/Tools_of_Trade/Tools_of_the_Trade.xml",
# "http://hrishimittal.com/rss",
# "http://octave.dk/feed/",
# "http://montreal.kijiji.ca/f-SearchAdRss",
# "http://blog.alezaa.com/rss",
# "http://www.bizbash.com/rss/news.xml",
# "http://www.heartwoodfarms.com/feed",
# "http://homepage.blogs.sapo.pt/data/rss",
# "http://www.cuponidad.com.pe/rssfeed.aspx",
# urls = [
# "http://www.lovelygirliebits.com/feeds/posts/default",
# "http://www.51arch.com/feed/",
# "http://mutelife.com/feed/",
# "http://learninginnovation.adampalin.co.uk/feed/",
# "http://insurancesearch101.com/rss",
# "http://www.87am.com/rss",
# "http://www.zumios.com/feed/",
# "http://adviso.hr/feed/",
# "http://comofas.com/rss",
# "http://feeds2.feedburner.com/shaunv",
# "http://feedproxy.google.com/TechCrunch",
# "http://gothamconsultancy.moonfruit.com/feeds/blogposts",
# "http://kruzo.dk/rss",
# "http://feeds.feedburner.com/scmagazinehome",
# "http://www.tecdencias.com/wp26/",
# "http://www.ilmareunisce.com/feed/",
# "http://rss.golem.de/rss.php",
# "http://fuckyeahgaming.com/feed/",
# "http://www.zaudhaus.com/feed/",
# "http://cts.tradepub.com/cts4/",
# "http://www.digitalgist.com/feeds/posts/default"
# ]
urls = []
100.times do |n|
# urls << "http://www.lovelygirliebits.com/feeds/posts/default"
urls << "http://feeds.feedburner.com/EverythingGirlie"
end
p urls.size
Benchmark::bmbm do |x|
x.report("http_client_pre") do
uri = URI.parse(urls.first)
client = HTTP::Client.new(:default_host => "#{uri.scheme}://#{uri.host}")
urls.each do |url|
body = client.get(uri.request_uri)
end
end
x.report("http_client") do
urls.each do |url|
uri = URI.parse(url)
client = HTTP::Client.new(:default_host => "#{uri.scheme}://#{uri.host}")
body = client.get(uri.request_uri)
end
end
x.report("http-request") do
urls.each do |url|
response = HttpRequest.get(url)
response.body
end
end
x.report("http-request pool") do
urls.each do |url|
pool = HttpRequest.pool(:bench)
response = pool.get(url)
response.body
end
end
# x.report("http-tony") do
# urls.each do |url|
# # response = Http.accept("text/xml").with_headers('Accept-Encoding' => 'gzip').with_response(:body).with_follow(true).get(url, "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17")
# # response = Http.with_headers('Accept-Encoding' => 'gzip').with_response(:object).with_follow(true).get(url, "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17")
# response = Http.accept("text/xml").with_response(:object).with_follow(true).get(url, "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17")
# response.body
# end
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment