Skip to content

Instantly share code, notes, and snippets.

@pochi
Created May 6, 2012 16:00
Show Gist options
  • Save pochi/2623085 to your computer and use it in GitHub Desktop.
Save pochi/2623085 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require "net/http"
threads = []
def ping_pong(num)
Net::HTTP.start("localhost", 4567) do |http|
http.get("/login.json?id=#{num.to_s}")
end
loop do
Net::HTTP.start("localhost", 4567) do |http|
http.get("/update.json?id=#{num.to_s}")
end
if rand(10) == 5 #=> 1/10
Net::HTTP.start("localhost", 4567) do |http|
http.get("/post.json?id=#{num.to_s}&message=pochi")
end
end
sleep 1
end
end
1000.times do |i|
threads << Thread.new(i) do |num|
ping_pong(num)
end
end
threads.each { |t| t.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment