Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created January 6, 2012 21:03
Show Gist options
  • Save jcoglan/1572388 to your computer and use it in GitHub Desktop.
Save jcoglan/1572388 to your computer and use it in GitHub Desktop.

Thin vs Puma

Run these two servers using the commands given in their source. Benchmark using:

ab -n 1000 -c 1000 http://localhost:8000/

I found thin can handle these requests without a problem. puma drops connections and causes ab to exit early.

With 200 threads, puma can handle 200 requests but does not respond promptly:

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4  915 1378.1      5    2991
Processing: 20096 20550 2063.8  20298   37213
Waiting:    20095 20487 2070.2  20238   37213
Total:      20160 21466 2654.2  20416   40203

Percentage of the requests served within a certain time (ms)
  50%  20416
  66%  20436
  75%  23104
  80%  23182
  90%  23262
  95%  23270
  98%  23270
  99%  40203
 100%  40203 (longest request)
# thin start -R async.ru -p 8000
# rackup async.ru -s thin -p 8000
# rainbows async.ru -c rainbows.conf -p 8000
require 'eventmachine'
app = lambda do |env|
cb = env['async.callback']
EM.add_timer(20) do
cb.call [200, {'Content-Type' => 'text/plain'}, ['Hello, world!']]
end
throw :async
end
run app
# ruby goliath.rb -svp 8000
require 'goliath'
class HelloWorld < Goliath::API
def response(env)
cb = env['async.callback']
EM.add_timer(20) do
cb.call [200, {'Content-Type' => 'text/plain'}, ['Hello, world!']]
end
[-1, {}, []]
end
end
Rainbows! { use :EventMachine }
# puma sync.ru -b tcp://0.0.0.0:8000 -t 0:1000
require 'eventmachine'
Thread.new { EM.run }
app = lambda do |env|
response = nil
EM.add_timer(20) do
response = [200, {'Content-Type' => 'text/plain'}, ['Hello, world!']]
end
Thread.pass until response
response
end
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment