What have you found for these years?

2010-05-06

async thin (open-uri vs em-http) (2)

em-http would be 10 times faster than open-uri
(actually, it's max([time(requests)]) vs sum([time(requests)])

url = 'http://graph.facebook.com/spellbook'
times = 10
require 'open-uri'
require 'em-http'
require 'async-rack'

run Builder.new{
use ContentType
map('/async'){
run lambda{ |env|
multi = EM::MultiRequest.new
times.times{
multi.add(EM::HttpRequest.new(url).get)
}
multi.callback{
env['async.callback'].call [200, {}, [
multi.responses[:succeeded].first.response
]]
}
throw :async
}
}
map('/sync'){
run lambda{ |env|
s = nil
times.times{ s = open(url).read }
[200, {}, [s]]
}
}
}

0 retries:

Post a Comment

All texts are licensed under CC Attribution 3.0