Created
May 10, 2012 13:28
-
-
Save courtneycouch/2652991 to your computer and use it in GitHub Desktop.
vertx server test
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
ar http = require('http'); | |
var fs = require('fs'); | |
var util = require('util'); | |
var fileCache; | |
var sendFile = function(conn, file) { | |
conn.writeHead(200, {"Content-Type": "text/html", "Content-Length": file.length}); | |
conn.write(file); | |
conn.end(); | |
} | |
http.createServer(function (req, res) { | |
if (fileCache == undefined) { | |
fs.readFile("foo.html", function(err, file) { | |
fileCache = file; | |
sendFile(res, fileCache); | |
}); | |
} else { | |
sendFile(res, fileCache); | |
} | |
}).listen(8080, 'localhost'); |
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
load('vertx.js') | |
var fileCache; | |
var sendFile = function(req, file) { | |
req.response.headers["Content-Length"] = file.length() | |
req.response.headers["Content-Type"] = "text/html" | |
req.response.end(file) | |
} | |
vertx.createHttpServer().requestHandler(function(req) { | |
if (fileCache == undefined) { | |
vertx.fileSystem.readFile("httpperf/foo.html" function(err, file) { | |
fileCache = file; | |
sendFile(req, fileCache); | |
}); | |
} else { | |
sendFile(req, fileCache); | |
} | |
}); | |
}).listen(8080, 'localhost'); |
Yea I didn't really spend any time on this.. just a few minutes changing the IO silliness (oh and the other benchmark showing node on multiple cores). I really should have tried mmap as well but really I should be spending my time doing actual stuff instead of making benchmarks hah. I think I made my point though that vertx isn't simply 5x faster than node as is being propagated.
i found an blog post on my readitlater list about couchdb but this blog post is about benchmarking.
http://jan.prima.de/~jan/plok/archives/175-Benchmarks-You-are-Doing-it-Wrong.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@courtneycouch You can save a syscall in the node server if you do
res.end(file)
rather thanres.write(file);res.end()