Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created April 2, 2014 22:26
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 kenichi/9944480 to your computer and use it in GitHub Desktop.
Save kenichi/9944480 to your computer and use it in GitHub Desktop.
using sinatra/puma to test long-wait calls to other services from angelo/reel
$ be ruby concurrency_test_app.rb -p 5000
I, [2014-04-02T15:15:12.467887 #1602] INFO -- : Angelo 0.1.5
I, [2014-04-02T15:15:12.468080 #1602] INFO -- : listening on 127.0.0.1:5000
D, [2014-04-02T15:15:27.794593 #1602] DEBUG -- : 127.0.0.1 - - "GET /asynch_test HTTP/1.1" 200 11
D, [2014-04-02T15:15:28.887823 #1602] DEBUG -- : 127.0.0.1 - - "GET /asynch_test HTTP/1.1" 200 11
require 'angelo'
require 'http'
class ConcurrencyTestApp < Angelo::Base
get '/asynch_test' do
HTTP.get('http://localhost:4567/wait', socket_class: Celluloid::IO::TCPSocket).response.body
end
end
ConcurrencyTestApp.run
require 'sinatra'
get '/wait' do
sleep 5
'hello world'
end
$ ruby sin_wait.rb -o 127.0.0.1
Puma 2.7.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://127.0.0.1:4567
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from Puma
127.0.0.1 - - [02/Apr/2014 15:15:27] "GET /wait HTTP/1.1" 200 11 5.0065
127.0.0.1 - - [02/Apr/2014 15:15:28] "GET /wait HTTP/1.1" 200 11 5.0015
$ date +'%s' ; time curl http://localhost:5000/asynch_test
1396476922
hello world
real 0m5.032s
user 0m0.006s
sys 0m0.004s
$ date +'%s'; time curl http://localhost:5000/asynch_test
1396476923
hello world
real 0m5.014s
user 0m0.006s
sys 0m0.004s
@kenichi
Copy link
Author

kenichi commented Apr 2, 2014

note that the timings in the terms are a second apart, yet each took 5s to finish (not 5 on first and 10 on second as previous attempts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment