Skip to content

Instantly share code, notes, and snippets.

@Evangenieur
Forked from grosser/Readme.md
Created March 27, 2011 23:30
Show Gist options
  • Save Evangenieur/889761 to your computer and use it in GitHub Desktop.
Save Evangenieur/889761 to your computer and use it in GitHub Desktop.
Ruby Server / Node.js Benchmark

Sinatra

ruby 1.9.2 + async_sinatra + thin thin start

ab -n 10000 -c 100 http://localhost:3000/
-> 49ms / request

Node

node server.js

ab -n 10000 -c 100 http://localhost:3000/
-> 20ms / request

EventMachine HttpServer

ruby em_http_serv.rb

ab -n 10000 -c 100 http://localhost:3000/
-> 12ms / request

Goliath

ruby hello.rb -e prod -p 3000

ab -n 10000 -c 100 http://localhost:3000/
-> 50ms / request
#!/usr/bin/env
require 'sinatra/async'
class AsyncTest < Sinatra::Base
register Sinatra::Async
aget '/' do
body "hello async"
end
end
run AsyncTest.new
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
class Handler < EventMachine::Connection
include EventMachine::HttpServer
def process_http_request
resp = EventMachine::DelegatedHttpResponse.new( self )
resp.status = 200
resp.content = "Hello World\n"
resp.send_response
end
end
EventMachine::run {
EventMachine.epoll
EventMachine::start_server("0.0.0.0", 3000, Handler)
puts "Listening..."
}
require 'goliath'
class Hello < Goliath::API
def response(env)
[200, {}, "Hello World!"]
end
end
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(3000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
@CloudMarc
Copy link

I note that bare sinatra isn't included - my impression is that Sinatra::Async is for downstream optimization (e.g. don't block on db reads), because plain old sinatra with thin already has upstream asynch.

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