An authentication server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

76 lines
1.4 KiB

require "socket"
require "socket/udp_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 = UDPSocket.new
soc.connect "localhost", 3000
mutex = Mutex.new
curr=Time.now
spawn do
curr2=Time.now
while endt+Time::Span.new(0,0,4)>curr2
begin
message : String | Nil = nil
mutex.synchronize do
message, addr = soc.receive
end
mess = JSON.parse message.not_nil!
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
curr2=Time.now
Fiber.yield
end
end
curr=Time.now
while endt+Time::Span.new(0,0,4)>curr
data = Hash{"user" => "dummy@example.org", "api_token" => "576231a1-18e6-4fbd-b058-b9d23fa1b456", "curr" => curr.to_unix_f}.to_json
mutex.synchronize do
soc.send data
end
cnt_s.add 1
curr = Time.now
Fiber.yield
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