Skip to content

Instantly share code, notes, and snippets.

@ctrochalakis
Created June 13, 2010 06:08
Show Gist options
  • Save ctrochalakis/436394 to your computer and use it in GitHub Desktop.
Save ctrochalakis/436394 to your computer and use it in GitHub Desktop.
Fun with async webserver
-> ab -c 10 -n 10 http://localhost:3000/timer
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: thin
Server Hostname: localhost
Server Port: 3000
Document Path: /timer
Document Length: 5 bytes
Concurrency Level: 10
* => Time taken for tests: 2.038 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 1230 bytes
HTML transferred: 50 bytes
Requests per second: 4.91 [#/sec] (mean)
Time per request: 2037.824 [ms] (mean)
Time per request: 203.782 [ms] (mean, across all concurrent requests)
Transfer rate: 0.59 [Kbytes/sec] received
# ruby 1.9
# gem install thin sinatra rack-fiber_pool
#
# thin -R config.ru start
require 'fiber'
require 'rack/fiber_pool'
use Rack::FiberPool
require 'sinatra'
Sinatra::Base.set(:run, false)
Sinatra::Base.set(:env, :production)
puts "Starting"
require './timer'
run Sinatra::Application
require 'sinatra'
get '/timer' do
f = Fiber.current
EventMachine::add_timer(2) { f.resume }
# give control
Fiber.yield
'ended'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment