Skip to content

Instantly share code, notes, and snippets.

@minoritea
Created February 2, 2013 01:41
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 minoritea/4695574 to your computer and use it in GitHub Desktop.
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.
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)
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)
$ 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