Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created August 10, 2010 07:33
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 phiggins/516856 to your computer and use it in GitHub Desktop.
Save phiggins/516856 to your computer and use it in GitHub Desktop.
require 'em-http'
N = 10
files = (0...N).map do |n|
file = "test_file_#{n}"
File.open( file, "w" ) do |f|
100_000.times { f << "0123456789" }
end
file
end
c = 4
pending = files.size
before = Time.now
puts "files: #{pending} of size #{File.size(files.first) / 1024}K"
puts "concurrency: #{c}"
EM.run do
q = EM::Queue.new
q.push(*files)
worker = lambda do |file|
http = EM::HttpRequest.new("http://192.168.213.1:4567/").put(:file => file)
#http = EM::HttpRequest.new("http://192.168.213.1:4567/").put(:body => File.binread(file))
http.callback do
pending -= 1
EM.stop if pending < 1
q.pop worker
end
http.errback do
puts http.error
end
http.errback do
pending -= 1
EM.stop if pending < 1
q.pop worker
end
end
c.times do
q.pop worker
end
EM.add_periodic_timer(1) do
puts q.size
end
end
puts "finished in #{Time.now - before}"
require 'sinatra'
put "/" do
puts "received #{request.body.size / 1024}K file"
"OK"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment