Skip to content

Instantly share code, notes, and snippets.

@sidoh
Created November 9, 2017 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidoh/7afadcfa9128baa5fd58fadea132621a to your computer and use it in GitHub Desktop.
Save sidoh/7afadcfa9128baa5fd58fadea132621a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'timeout'
require 'socket'
require 'net/http'
NUM_TRIALS = 1000
hits = 0
command_client = Net::HTTP.new('10.133.8.158')
command_request = Net::HTTP::Put.new('/gateways/10/cct/0')
command_request.body = '{"status":"off"}'
listen_client = Net::HTTP.new('10.133.8.138')
listen_request = Net::HTTP::Get.new('/gateway_traffic')
NUM_TRIALS.times do |x|
x += 1
t = Thread.new do
begin
Timeout::timeout(0.5) do
listen_client.request(listen_request)
hits += 1
end
rescue Exception => e
end
end
printf "%d...", x
command_client.request(command_request)
t.join
printf "%d (%f)\n", hits, (hits.to_f/x)*100
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment