From f2d5cea73a53c59ce6314ecdf27bbf341e0465a2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 9 Apr 2013 02:04:38 +0400 Subject: [PATCH] benchmark: add chunked-encoding benchmark --- benchmark/http/chunked.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 benchmark/http/chunked.js diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js new file mode 100644 index 00000000000..bead074dc1a --- /dev/null +++ b/benchmark/http/chunked.js @@ -0,0 +1,42 @@ +// When calling .end(buffer) right away, this triggers a "hot path" +// optimization in http.js, to avoid an extra write call. +// +// However, the overhead of copying a large buffer is higher than +// the overhead of an extra write() call, so the hot path was not +// always as hot as it could be. +// +// Verify that our assumptions are valid. + +var common = require('../common.js'); +var PORT = common.PORT; + +var bench = common.createBenchmark(main, { + num: [1, 4, 8, 16], + size: [1, 64, 256], + c: [100] +}); + +function main(conf) { + http = require('http'); + var chunk = new Buffer(conf.size); + chunk.fill('8'); + + var args = ['-r', 5000, '-t', 8, '-c', conf.c]; + + var server = http.createServer(function(req, res) { + function send(left) { + if (left === 0) return res.end(); + res.write(chunk); + setTimeout(function() { + send(left - 1); + }, 0); + } + send(conf.num); + }); + + server.listen(common.PORT, function() { + bench.http('/', args, function() { + server.close(); + }); + }); +}