Skip to content

Instantly share code, notes, and snippets.

@mostlyobvious
Forked from mlomnicki/gist:890485
Created April 2, 2011 21:27
Show Gist options
  • Save mostlyobvious/899917 to your computer and use it in GitHub Desktop.
Save mostlyobvious/899917 to your computer and use it in GitHub Desktop.
ab -n 10000 -c 100 http://localhost:8000
eventmachine:
Requests per second: 2495.36 [#/sec] (mean)
Time per request: 40.074 [ms] (mean)
node.js:
Requests per second: 1461.95 [#/sec] (mean)
Time per request: 68.402 [ms] (mean)
# gem install eventmachine eventmachine_httpserver em-mysql mysqlplus
require 'eventmachine'
require 'evma_httpserver'
require 'em/mysql'
EventedMysql.settings.update :host => "127.0.0.1", :port => 3306, :database => "mysql"
module HttpServer
include EM::HttpServer
def process_http_request
response = EM::DelegatedHttpResponse.new(self)
response.content_type 'text/html'
response.status = 200
EventedMysql.select("SELECT NOW() AS time") do |result|
response.content = result.first["time"]
response.send_response
end
end
end
EM.run do
EM.start_server "127.0.0.1", 8000, HttpServer
end
// npm install mysql
var http = require('http');
var mysql = require('mysql');
var client = new mysql.Client();
client.user = "root";
client.connect();
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
client.query("SELECT NOW() AS time", function(err, result, fields) {
res.write(result[0].time.toString());
res.end();
});
}).listen(8000, 'localhost');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment