-
-
Save knowtheory/e3c370ad28a6503a9cf6 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
require 'sinatra' | |
require 'json' | |
post '/endpoint' do | |
puts JSON.parse(request['json']) | |
end |
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
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Thin | |
Thin web server (v1.6.2 codename Doc Brown) | |
Maximum connections set to 1024 | |
Listening on localhost:4567, CTRL+C to stop | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:46:05] "POST /endpoint HTTP/1.1" 200 - 0.0056 | |
{"1"=>10, "2"=>10, "3"=>10, "4"=>10, "5"=>10, "6"=>10, "7"=>10, "8"=>10, "9"=>10, "10"=>10} | |
127.0.0.1 - - [03/Jun/2014 10:46:35] "POST /endpoint HTTP/1.1" 200 - 0.0010 | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:47:05] "POST /endpoint HTTP/1.1" 200 - 0.0009 | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:47:35] "POST /endpoint HTTP/1.1" 200 - 0.0010 | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:48:05] "POST /endpoint HTTP/1.1" 200 - 0.0006 | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:48:35] "POST /endpoint HTTP/1.1" 200 - 0.0005 | |
{} | |
127.0.0.1 - - [03/Jun/2014 10:49:05] "POST /endpoint HTTP/1.1" 200 - 0.0007 |
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
--- flushed --- | |
--- flushed --- | |
10: 1 | |
10: 2 | |
10: 3 | |
10: 4 | |
10: 5 | |
10: 6 | |
10: 7 | |
10: 8 | |
10: 9 | |
10: 10 | |
--- flushed --- | |
--- flushed --- | |
--- flushed --- | |
--- flushed --- | |
--- flushed --- | |
--- flushed --- |
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
require 'net/http' | |
def make_requests(keys, count) | |
# Each key gets its own thread | |
threads = keys.map do |key| | |
# each key also gets it's own count | |
key_count = 0 | |
Thread.new do | |
# Each key requests the number of requests specified by the count. | |
Net::HTTP.start('localhost', '5999') do |requester| | |
until key_count >= count | |
sleep(rand(3)) | |
puts "Requesting #{key}" | |
requester.get("/pixel.gif?key=#{key}") | |
key_count += 1 | |
end | |
end | |
end | |
end | |
threads.each{ |t| t.join } | |
end | |
make_requests(1..10, 10) |
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
{ | |
"port": "5999", | |
"host": "localhost", | |
"interval": 30, | |
"endpoint": "http://localhost:4567/endpoint" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment