Created
October 13, 2012 07:49
-
-
Save timurvafin/3883733 to your computer and use it in GitHub Desktop.
Get http requests benchmark: sync vs. celluloid vs. em
This file contains hidden or 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
source :rubygems | |
gem 'celluloid' | |
gem 'em-synchrony' | |
gem 'em-http-request' |
This file contains hidden or 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
user system total real | |
em: 2.440000 0.510000 2.950000 ( 4.980928) | |
celluloid: 3.610000 0.910000 4.520000 ( 6.500888) |
This file contains hidden or 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
require 'rubygems' | |
require 'bundler/setup' | |
require 'benchmark' | |
N = 2_000 | |
POOL_SIZE = 50 | |
URLS = ["http://ya.ru"] * N | |
require 'net/http' | |
class NetHttpTest | |
def get(url) | |
Net::HTTP.get_response(URI(url)).message | |
end | |
def self.test | |
URLS.map {|url| new.get(url) } | |
end | |
end | |
require 'celluloid' | |
class CelluloidTest | |
include Celluloid | |
Celluloid.logger = nil | |
def get(url) | |
Net::HTTP.get_response(URI(url)).message | |
end | |
def self.test | |
pool = self.pool(size: POOL_SIZE) | |
futures = URLS.map {|url| pool.future.get(url) } | |
futures.map(&:value) | |
end | |
end | |
require 'em-synchrony' | |
require 'em-synchrony/em-http' | |
require 'em-synchrony/fiber_iterator' | |
class EmHttpRequest | |
def get(url) | |
EventMachine::HttpRequest.new(url).get.response_header.status | |
end | |
def self.test | |
results = [] | |
EM.synchrony do | |
EM::Synchrony::FiberIterator.new(URLS, POOL_SIZE).each do |url| | |
results.push new.get(url) | |
end | |
EventMachine.stop | |
end | |
results | |
end | |
end | |
Benchmark.bm do |x| | |
# x.report('sync: ') { NetHttpTest.test } | |
x.report('em: ') { EmHttpRequest.test } | |
x.report('celluloid: ') { CelluloidTest.test } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is Celluloid that much slower than event-machine for http requests?