Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

benchmark scripts / results (from excon)

  • Loading branch information...
commit 536ff956c000fe3fdc1652a9dd1239fe93b67cc1 1 parent 000579b
@igrigorik authored
View
13 Gemfile
@@ -1,3 +1,14 @@
source "http://rubygems.org"
-gemspec
+gemspec
+
+group :benchmark do
+ gem 'httparty'
+ gem 'rest-client'
+ gem 'tach', '0.0.8'
+ gem 'typhoeus'
+ gem 'sinatra'
+ gem 'streamly_ffi'
+ gem 'curb'
+ gem 'excon'
+end
View
137 benchmarks/clients.rb
@@ -0,0 +1,137 @@
+$: << './benchmarks'
+require 'server'
+
+require 'excon'
+require 'httparty'
+require 'net/http'
+require 'open-uri'
+require 'rest_client'
+require 'tach'
+require 'typhoeus'
+
+url = 'http://localhost:9292/data/1000'
+
+with_server do
+ Tach.meter(1000) do
+
+ tach('curb (persistent)') do |n|
+ curb = Curl::Easy.new
+
+ n.times do
+ curb.url = url
+ curb.http_get
+ curb.body_str
+ end
+ end
+
+ tach('em-http-request') do |n|
+ EventMachine.run {
+ count = 0
+
+ n.times do
+ http = EventMachine::HttpRequest.new(url).get
+
+ http.callback {
+ count += 1
+ EM.stop if count == n
+ }
+
+ http.errback {
+ count += 1
+ EM.stop if count == n
+ }
+ end
+ }
+ end
+
+ tach('em-http-request (persistent)') do |n|
+ EventMachine.run {
+ count = 0
+ conn = EventMachine::HttpRequest.new(url)
+
+ n.times do
+ http = conn.get :keepalive => true
+ http.callback {
+ count += 1
+ EM.stop if count == n
+ }
+
+ http.errback {
+ count += 1
+ EM.stop if count == n
+ }
+ end
+ }
+ end
+
+ tach('Excon') do
+ Excon.get(url).body
+ end
+
+ excon = Excon.new(url)
+ tach('Excon (persistent)') do
+ excon.request(:method => 'get').body
+ end
+
+ tach('HTTParty') do
+ HTTParty.get(url).body
+ end
+
+ tach('Net::HTTP') do
+ # Net::HTTP.get('localhost', '/data/1000', 9292)
+ Net::HTTP.start('localhost', 9292) {|http| http.get('/data/1000').body }
+ end
+
+ Net::HTTP.start('localhost', 9292) do |http|
+ tach('Net::HTTP (persistent)') do
+ http.get('/data/1000').body
+ end
+ end
+
+ tach('open-uri') do
+ open(url).read
+ end
+
+ tach('RestClient') do
+ RestClient.get(url)
+ end
+
+ streamly = StreamlyFFI::Connection.new
+ tach('StreamlyFFI (persistent)') do
+ streamly.get(url)
+ end
+
+ tach('Typhoeus') do
+ Typhoeus::Request.get(url).body
+ end
+
+ end
+end
+
+# +------------------------------+----------+
+# | tach | total |
+# +------------------------------+----------+
+# | em-http-request (persistent) | 1.769685 |
+# +------------------------------+----------+
+# | Excon (persistent) | 1.810310 |
+# +------------------------------+----------+
+# | Typhoeus | 1.971168 |
+# +------------------------------+----------+
+# | curb (persistent) | 1.975028 |
+# +------------------------------+----------+
+# | StreamlyFFI (persistent) | 2.101071 |
+# +------------------------------+----------+
+# | Excon | 2.427039 |
+# +------------------------------+----------+
+# | Net::HTTP | 2.891856 |
+# +------------------------------+----------+
+# | em-http-request | 3.037968 |
+# +------------------------------+----------+
+# | HTTParty | 3.043875 |
+# +------------------------------+----------+
+# | Net::HTTP (persistent) | 3.094460 |
+# +------------------------------+----------+
+# | RestClient | 3.174572 |
+# +------------------------------+----------+
+# | open-uri | 3.467549 |
+# +------------------------------+----------+
View
71 benchmarks/em-excon.rb
@@ -0,0 +1,71 @@
+$: << './benchmarks'
+require 'server'
+
+url = 'http://127.0.0.1:9292/data/1000'
+
+with_server do
+ Tach.meter(1000) do
+
+ # excon = Excon.new(url)
+ # tach('Excon (persistent)') do
+ # excon.request(:method => 'get').body
+ # end
+ #
+ # tach('Excon') do
+ # Excon.get(url).body
+ # end
+
+ tach('em-http-request') do |n|
+ EventMachine.run {
+ count = 0
+ n.times do
+ http = EventMachine::HttpRequest.new(url).get
+
+ http.callback {
+ count += 1
+ EM.stop if count == n
+ }
+
+ http.errback {
+ count += 1
+ EM.stop if count == n
+ }
+ end
+ }
+ end
+
+ # tach('em-http-request (persistent)') do |n|
+ # EventMachine.run {
+ # count = 0
+ # conn = EventMachine::HttpRequest.new(url)
+ #
+ # n.times do
+ # http = conn.get :keepalive => true
+ # http.callback {
+ # count += 1
+ # EM.stop if count == n
+ # }
+ #
+ # http.errback {
+ # count += 1
+ # EM.stop if count == n
+ # }
+ # end
+ # }
+ # end
+ end
+end
+
+# [Excon (persistent), Excon, em-http-request, em-http-request (persistent)]
+#
+# +------------------------------+----------+
+# | tach | total |
+# +------------------------------+----------+
+# | em-http-request (persistent) | 1.691872 |
+# +------------------------------+----------+
+# | Excon (persistent) | 1.754767 |
+# +------------------------------+----------+
+# | Excon | 2.271368 |
+# +------------------------------+----------+
+# | em-http-request | 2.973122 |
+# +------------------------------+----------+
View
BIN  benchmarks/em-profile.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
65 benchmarks/em-profile.txt
@@ -0,0 +1,65 @@
+Total: 143 samples
+ 67 46.9% 46.9% 109 76.2% Kernel#gem_original_require
+ 17 11.9% 58.7% 17 11.9% garbage_collector
+ 12 8.4% 67.1% 12 8.4% EventMachine.connect_server
+ 11 7.7% 74.8% 11 7.7% Dir.[]
+ 11 7.7% 82.5% 11 7.7% File.file?
+ 4 2.8% 85.3% 4 2.8% Kernel#eval
+ 3 2.1% 87.4% 16 11.2% Enumerable#find
+ 3 2.1% 89.5% 3 2.1% Regexp#initialize
+ 2 1.4% 90.9% 16 11.2% EventMachine.run_machine
+ 2 1.4% 92.3% 2 1.4% Regexp#match
+ 1 0.7% 93.0% 1 0.7% FFI::DynamicLibrary.open
+ 1 0.7% 93.7% 1 0.7% Hash#values
+ 1 0.7% 94.4% 7 4.9% Kernel#load
+ 1 0.7% 95.1% 3 2.1% MIME::Type#initialize
+ 1 0.7% 95.8% 1 0.7% MatchData#captures
+ 1 0.7% 96.5% 13 9.1% Module#bind_connect
+ 1 0.7% 97.2% 17 11.9% Module#searcher
+ 1 0.7% 97.9% 1 0.7% String#downcase
+ 1 0.7% 98.6% 1 0.7% String#scan
+ 1 0.7% 99.3% 1 0.7% String#strip
+ 1 0.7% 100.0% 1 0.7% TCPSocket#initialize
+ 0 0.0% 100.0% 1 0.7% Array#map
+ 0 0.0% 100.0% 14 9.8% Array#reverse_each
+ 0 0.0% 100.0% 14 9.8% Class#from_gems_in
+ 0 0.0% 100.0% 14 9.8% Class#from_installed_gems
+ 0 0.0% 100.0% 14 9.8% Class#load
+ 0 0.0% 100.0% 1 0.7% Class#parse
+ 0 0.0% 100.0% 1 0.7% Class#simplified
+ 0 0.0% 100.0% 6 4.2% Enumerable#each_with_index
+ 0 0.0% 100.0% 1 0.7% Excon::Connection#connect
+ 0 0.0% 100.0% 1 0.7% Excon::Connection#request
+ 0 0.0% 100.0% 1 0.7% Excon::Connection#socket
+ 0 0.0% 100.0% 1 0.7% FFI::Library#ffi_lib
+ 0 0.0% 100.0% 10 7.0% Gem::GemPathSearcher#find
+ 0 0.0% 100.0% 1 0.7% Gem::GemPathSearcher#find_active
+ 0 0.0% 100.0% 16 11.2% Gem::GemPathSearcher#init_gemspecs
+ 0 0.0% 100.0% 16 11.2% Gem::GemPathSearcher#initialize
+ 0 0.0% 100.0% 11 7.7% Gem::GemPathSearcher#matching_file?
+ 0 0.0% 100.0% 11 7.7% Gem::GemPathSearcher#matching_files
+ 0 0.0% 100.0% 14 9.8% Gem::SourceIndex#load_gems_in
+ 0 0.0% 100.0% 14 9.8% Gem::SourceIndex#refresh!
+ 0 0.0% 100.0% 1 0.7% Gem::SourceIndex#search
+ 0 0.0% 100.0% 1 0.7% HttpOptions#initialize
+ 0 0.0% 100.0% 1 0.7% HttpOptions#set_uri
+ 0 0.0% 100.0% 14 9.8% Integer#times
+ 0 0.0% 100.0% 1 0.7% Kernel#loop
+ 0 0.0% 100.0% 109 76.2% Kernel#require
+ 0 0.0% 100.0% 1 0.7% Module#activate
+ 0 0.0% 100.0% 13 9.1% Module#connect
+ 0 0.0% 100.0% 1 0.7% Module#get
+ 0 0.0% 100.0% 2 1.4% Module#load_full_rubygems_library
+ 0 0.0% 100.0% 5 3.5% Module#loaded_path?
+ 0 0.0% 100.0% 16 11.2% Module#meter
+ 0 0.0% 100.0% 16 11.2% Module#run
+ 0 0.0% 100.0% 16 11.2% Module#source_index
+ 0 0.0% 100.0% 30 21.0% Module#try_activate
+ 0 0.0% 100.0% 17 11.9% Object#with_server
+ 0 0.0% 100.0% 2 1.4% Regexp.union
+ 0 0.0% 100.0% 1 0.7% TCPSocket.open
+ 0 0.0% 100.0% 16 11.2% Tach::Meter#initialize
+ 0 0.0% 100.0% 16 11.2% Tach::Meter#run_tach
+ 0 0.0% 100.0% 1 0.7% URI::Parser#initialize
+ 0 0.0% 100.0% 1 0.7% URI::Parser#initialize_regexp
+ 0 0.0% 100.0% 7 4.9% YAML::EngineManager#yamler=
View
48 benchmarks/server.rb
@@ -0,0 +1,48 @@
+require 'excon'
+require 'httparty'
+require 'net/http'
+require 'open-uri'
+require 'rest_client'
+require 'tach'
+require 'typhoeus'
+require 'sinatra/base'
+require 'streamly_ffi'
+require 'curb'
+
+require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'em-http')
+
+module Benchmark
+ class Server < Sinatra::Base
+
+ def self.run
+ Rack::Handler::WEBrick.run(
+ Benchmark::Server.new,
+ :Port => 9292,
+ :AccessLog => [],
+ :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
+ )
+ end
+
+ get '/data/:amount' do |amount|
+ 'x' * amount.to_i
+ end
+
+ end
+end
+
+def with_server(&block)
+ pid = Process.fork do
+ Benchmark::Server.run
+ end
+ loop do
+ sleep(1)
+ begin
+ Excon.get('http://localhost:9292/api/foo')
+ break
+ rescue
+ end
+ end
+ yield
+ensure
+ Process.kill(9, pid)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.