Created
November 9, 2017 05:51
-
-
Save sidoh/7afadcfa9128baa5fd58fadea132621a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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