-
-
Save mostlyobvious/899917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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