Skip to content

Instantly share code, notes, and snippets.

@o-sam-o
Created June 3, 2011 06:11
Show Gist options
  • Save o-sam-o/1005945 to your computer and use it in GitHub Desktop.
Save o-sam-o/1005945 to your computer and use it in GitHub Desktop.
Hacky script that sloooowly posts data to a web app
require 'net/http'
url = URI.parse('http://localhost:7001/AppName')
class Producer
def initialize(thread_id)
@write_count = 0
@thread_id = thread_id
end
def size
return 10_000
end
def read ( how_much )
p "#{@thread_id} How much: #{how_much} Already Done: #{@write_count}"
return nil if @write_count > size
sleep 10
@write_count += how_much
return 'content=' + ('*' * (how_much - 8))
end
end
t = nil
(1..50).each do |thread_id|
sleep 1
t = Thread.new do
req = Net::HTTP::Post.new(url.path)
pro = Producer.new(thread_id)
req.body_stream = pro
req.content_length = pro.size
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
end
end
t.join
p "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment