Created
February 2, 2013 01:41
-
-
Save minoritea/4695574 to your computer and use it in GitHub Desktop.
Comparison between Celluloid::IO and Ruby's sockets in Celluloid.
Tests were executed on 2.3Ghz macbook.
The server was written in node.js and replies a HTTP response.
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
require 'celluloid/io' | |
require 'net/http' | |
t,addr = ARGV[0..1] | |
t = t.to_i | |
start = Time.now | |
class NetHttpBench | |
include Celluloid::IO | |
def get addr,t | |
(0...t).map do |i| | |
Net::HTTP.get_response URI("http://#{addr}/#{i}") | |
end | |
end | |
end | |
ret = NetHttpBench.new.get(addr,t).inject(Hash.new){|r,i| | |
r[i.code] = (r[i.code]||0) + 1 | |
r | |
} | |
p ret | |
p (Time.now - start) |
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
require 'celluloid' | |
require 'net/http' | |
t,addr = ARGV[0..1] | |
t = t.to_i | |
start = Time.now | |
class Client | |
include Celluloid | |
def get addr,i | |
Net::HTTP.get_response URI("http://#{addr}/#{i}") | |
end | |
end | |
ret = (0...t).map{|i| | |
Client.new.future.get addr,i | |
}.inject(Hash.new){|r,f| | |
v=f.value.code | |
r[v] = (r[v]||0) + 1 | |
r | |
} | |
p ret | |
p (Time.now - start) |
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
$ jruby client1.rb 1000 localhost:4567 | |
{"200"=>1000} | |
2.206 | |
$ jruby client1.rb 10000 localhost:4567 | |
{"200"=>10000} | |
8.26 | |
$ jruby client2.rb 1000 localhost:4567 | |
{"200"=>1000} | |
1.57 | |
$ jruby client2.rb 10000 localhost:4567 | |
ThreadError: unable to create new native thread |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment