require "http/web_socket"
|
|
require "json"
|
|
|
|
total = 0
|
|
min = 1000000000
|
|
max = 0
|
|
cnt_s = Atomic(Int32).new(0)
|
|
mutex_s = Mutex.new
|
|
|
|
cnt_r = Atomic(Int32).new(0)
|
|
mutex_r = Mutex.new
|
|
|
|
start = Time.now
|
|
duration=Time::Span.new(0,0,45)
|
|
endt = start+duration
|
|
|
|
(1..10).each do
|
|
spawn do
|
|
soc = HTTP::WebSocket.new URI.parse("http://127.0.0.1:3000/socket/user/authenticate")
|
|
|
|
soc.on_message do |message|
|
|
begin
|
|
mess = JSON.parse message
|
|
t = Time.now.to_unix_f - mess["curr"].as_f
|
|
mutex_r.synchronize do
|
|
min = Math.min(min, t)
|
|
max = Math.max(max, t)
|
|
total += t
|
|
cnt_r.add 1
|
|
end
|
|
rescue
|
|
puts message
|
|
end
|
|
end
|
|
|
|
spawn do
|
|
soc.run
|
|
end
|
|
|
|
curr=Time.now
|
|
while endt>curr
|
|
data = Hash{"user" => "dummy@example.org", "api_token" => "576231a1-18e6-4fbd-b058-b9d23fa1b456", "curr" => curr.to_unix_f}.to_json
|
|
soc.send data
|
|
cnt_s.add 1
|
|
curr = Time.now
|
|
end
|
|
end
|
|
end
|
|
|
|
scurr=Time.now
|
|
|
|
while scurr<endt+Time::Span.new(0,0,4)
|
|
scurr = Time.now
|
|
Fiber.yield
|
|
end
|
|
|
|
puts "avg: "+(total/cnt_r.get).to_s
|
|
puts "min: "+min.to_s
|
|
puts "max: "+max.to_s
|
|
puts "cnt_s: "+cnt_s.get.to_s
|
|
puts "cnt_r: "+cnt_r.get.to_s
|
|
puts "rps: "+(cnt_r.get/duration.seconds).to_s
|