并发测试代码

require "net/http"
require "uri"

term = Time.now
uri = URI.parse("http://192.168.1.113/spd/")
cnt = 0

1000.times do |i|
  Thread.new(uri) do |uri|
    # cnt = cnt + 1
    # p cnt

    http = Net::HTTP.new(uri.host, uri.port)
    http.request(Net::HTTP::Get.new(uri.request_uri))
  end
end

# p 'sleeping'
# sleep 3

printf("time: %1.3fsec\n", Time.now - term)

相关推荐