From 7a6bcbc3907d8e3d2131a684dc97e8dd74cf8aef Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 28 Aug 2012 23:21:44 -0700 Subject: [PATCH] switch to benchmarx --- Makefile | 17 +++--- README.md | 5 +- bench/README.md | 8 --- bench/buffet-server.js | 27 ++++++++++ bench/buffet.js | 8 +++ bench/ecstatic.js | 8 +++ bench/index.js | 89 ------------------------------- bench/lib/repeat.js | 5 -- bench/lib/siege.js | 30 ----------- bench/lib/summary.js | 32 ----------- bench/lib/utils.js | 9 ++++ bench/lib/version.js | 27 ---------- bench/middleware/buffet-server.js | 17 ------ bench/middleware/buffet.js | 3 -- bench/middleware/ecstatic.js | 3 -- bench/middleware/node-static.js | 6 --- bench/middleware/paperboy.js | 6 --- bench/middleware/send.js | 9 ---- bench/middleware/varnish.js | 20 ------- bench/node-static.js | 11 ++++ bench/opts.json | 3 ++ bench/package.json | 8 +-- bench/paperboy.js | 11 ++++ bench/send.js | 13 +++++ bench/varnish.js | 31 +++++++++++ package.json | 3 +- 26 files changed, 134 insertions(+), 275 deletions(-) create mode 100644 bench/buffet-server.js create mode 100644 bench/buffet.js create mode 100644 bench/ecstatic.js delete mode 100644 bench/index.js delete mode 100644 bench/lib/repeat.js delete mode 100755 bench/lib/siege.js delete mode 100644 bench/lib/summary.js create mode 100644 bench/lib/utils.js delete mode 100644 bench/lib/version.js delete mode 100644 bench/middleware/buffet-server.js delete mode 100644 bench/middleware/buffet.js delete mode 100644 bench/middleware/ecstatic.js delete mode 100644 bench/middleware/node-static.js delete mode 100644 bench/middleware/paperboy.js delete mode 100644 bench/middleware/send.js delete mode 100644 bench/middleware/varnish.js create mode 100644 bench/node-static.js create mode 100644 bench/opts.json create mode 100644 bench/paperboy.js create mode 100644 bench/send.js create mode 100644 bench/varnish.js diff --git a/Makefile b/Makefile index ca43824..63fe6da 100644 --- a/Makefile +++ b/Makefile @@ -3,17 +3,12 @@ test: --reporter spec \ --timeout 5s -bench: install-bench - @node bench - -check = \ - if [ -z `which siege` ]; then \ - echo "please install siege. http://www.joedog.org/siege-home/"; \ - exit 1; \ - fi - -install-bench: - @$(call check) +bench: @cd bench; npm install + @./node_modules/.bin/benchmarx \ + --title "buffet benchmarks" \ + --runner siege \ + --opts bench/opts.json \ + --path ",hello.txt,folder/Alice-white-rabbit.jpg" .PHONY: test bench \ No newline at end of file diff --git a/README.md b/README.md index c05895a..686af35 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,9 @@ Running your own benchmark Type `make bench` in the buffet directory (you'll need [siege](http://www.joedog.org/siege-home/) installed). -For [here](https://github.com/carlos8f/node-buffet/tree/master/bench) for the -benchmark source code and [here](https://gist.github.com/3473500) for my results. +Brought to you by [benchmarx](https://github.com/carlos8f/node-benchmarx). + +See [here](https://gist.github.com/3473500) for my results. - - - diff --git a/bench/README.md b/bench/README.md index 1bc362c..088ac20 100644 --- a/bench/README.md +++ b/bench/README.md @@ -14,14 +14,6 @@ In the buffet root, run: $ make bench ``` -Or to run a specific benchmark, - -```bash -$ node bench [time] [wait] -``` - -Time defaults to `30` (seconds), and `wait` to `10` (seconds) between tests. - My results ---------- diff --git a/bench/buffet-server.js b/bench/buffet-server.js new file mode 100644 index 0000000..b9aba2b --- /dev/null +++ b/bench/buffet-server.js @@ -0,0 +1,27 @@ +var execFile = require('child_process').execFile + , utils = require('./lib/utils') + , buffet + +exports.name = 'buffet-server'; +exports.version = utils.version(exports.name); + +exports.listen = function (options, cb) { + var port = randomPort() + , buffetRoot = utils.resolve(__dirname, '..') + + console.log(options); + buffet = execFile(buffetRoot + '/bin/buffet.js', ['-p', port, '--no-log', '--no-watch'], {cwd: options.root}); + buffet.stderr.on('data', function (chunk) { + if (chunk.toString().match(/listening/)) { + cb(null, port); + } + }); +}; + +exports.close = function () { + buffet.kill(); +}; + +function randomPort () { + return Math.round((Math.random() * 2e4) + 2e4); +} \ No newline at end of file diff --git a/bench/buffet.js b/bench/buffet.js new file mode 100644 index 0000000..77bc11b --- /dev/null +++ b/bench/buffet.js @@ -0,0 +1,8 @@ +var utils = require('./lib/utils') + +exports.name = 'buffet'; +exports.version = utils.version(exports.name); + +exports.middleware = function (options) { + return require('../')(options.root); +}; \ No newline at end of file diff --git a/bench/ecstatic.js b/bench/ecstatic.js new file mode 100644 index 0000000..e98915b --- /dev/null +++ b/bench/ecstatic.js @@ -0,0 +1,8 @@ +var utils = require('./lib/utils') + +exports.name = 'ecstatic'; +exports.version = utils.version(exports.name); + +exports.middleware = function (options) { + return require('ecstatic')(options.root); +}; \ No newline at end of file diff --git a/bench/index.js b/bench/index.js deleted file mode 100644 index eee68c6..0000000 --- a/bench/index.js +++ /dev/null @@ -1,89 +0,0 @@ -var server = require('http').createServer() - , middler = require('middler') - , glob = require('glob') - , async = require('async') - , root = require('path').resolve(__dirname, '../test/files') - , getVersion = require('./lib/version') - , siege = require('./lib/siege') - , basename = require('path').basename - , summary = require('./lib/summary') - , repeat = require('./lib/repeat') - , test = process.argv[2] || '*' - , time = parseInt(process.argv[3] || 30, 10) - , wait = parseInt(process.argv[4] || 10, 10) - -console.log('\nnode-buffet benchmarks\n' + new Date() + '\n'); - -server.listen(0, function () { - var port = server.address().port; - - glob('middleware/' + test + '.js', {cwd: __dirname}, function (err, matches) { - if (err) throw err; - - // randomize order - matches.sort(function () { return 0.5 - Math.random() }); - - var results = {} - , coolOff = 0 - - var tasks = matches.map(function (match) { - return function (cb) { - var mod = basename(match, '.js'); - - function onErr (err) { - console.error(err, '\n'); - cb(); - } - - getVersion(mod, function (err, version) { - if (err) return onErr(err); - - var summaryKey = mod + '@' + version - , header = summaryKey + '\n' + repeat('-', summaryKey.length) - - console.log(header + '\n'); - - function siegeAfterCooloff (port) { - setTimeout(function () { - siege(mod, port, time, function (err, proc) { - if (err) return onErr(err); - proc.stderr.pipe(process.stdout); - var output = ''; - proc.stderr.on('data', function (chunk) { - output += chunk; - }); - proc.once('close', function (code) { - if (code) return onErr(new Error('siege exited with code ' + code)); - results[summaryKey] = output; - cb(); - }); - }); - }, coolOff); // "cool off" between benchmarks - coolOff = wait; - } - - var middleware = require('./' + match)({root: root}, function (err, port) { - if (err) return onErr(err); - siegeAfterCooloff(port); - }); - - if (middleware) { - middler(server) - .removeAll() - .add(middleware); - - siegeAfterCooloff(port); - } - }); - }; - }); - - async.series(tasks, function (err) { - if (err) throw err; - - console.log(summary(results)); - server.close(); - process.exit(); - }); - }); -}); \ No newline at end of file diff --git a/bench/lib/repeat.js b/bench/lib/repeat.js deleted file mode 100644 index 68dcd58..0000000 --- a/bench/lib/repeat.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function repeat (c, len) { - var ret = ''; - while (ret.length < len) ret += c; - return ret; -}; \ No newline at end of file diff --git a/bench/lib/siege.js b/bench/lib/siege.js deleted file mode 100755 index 294338b..0000000 --- a/bench/lib/siege.js +++ /dev/null @@ -1,30 +0,0 @@ -var spawn = require('child_process').spawn - , idgen = require('idgen') - , fs = require('fs') - , glob = require('glob') - , buffetRoot = require('path').resolve(__dirname, '../..') - -module.exports = function (test, port, time, cb) { - var id = test + '-' + idgen() - , prefix = '/tmp/buffet-benchmark-' + id - , logFilePath = prefix + '.log' - , urlFilePath = prefix + '-urls.txt' - , baseUrl = 'http://127.0.0.1:' + port + '/' - , args = ['-b', '-t', time + 's', '--log=' + logFilePath, '-f', urlFilePath]; - - glob('**', {cwd: buffetRoot + '/test/files'}, function (err, matches) { - var urls = matches.filter(function (match) { - if (match === 'folder') return false; - return true; - }).map(function (path) { - return baseUrl + path; - }); - - fs.writeFile(urlFilePath, urls.join('\n'), function (err) { - if (err) return cb(err); - var siege = spawn('siege', args); - siege.once('close', fs.unlink.bind(fs, urlFilePath)); - cb(null, siege); - }); - }); -}; \ No newline at end of file diff --git a/bench/lib/summary.js b/bench/lib/summary.js deleted file mode 100644 index 72caaca..0000000 --- a/bench/lib/summary.js +++ /dev/null @@ -1,32 +0,0 @@ -var repeat = require('./repeat') - -module.exports = function (results) { - var items = [] - , high = 0 - , low = 1e5 - - Object.keys(results).forEach(function (k) { - var output = results[k]; - var item = {}; - item.mod = k; - item.rps = parseFloat(output.match(/([\d\.]+) trans\/sec/)[1]); - items.push(item); - high = Math.max(item.rps, high); - low = Math.min(item.rps, low); - }); - - var variance = high - low - , star = variance / 5 - - items.sort(function (a, b) { - if (a.rps < b.rps) return 1; - if (a.rps > b.rps) return -1; - return 0; - }); - - return 'SUMMARY\n-------\n\n' + items.reduce(function (prev, item, idx, arr) { - var stars = Math.min(5, Math.max(1, Math.round(item.rps / star))); - - return prev + repeat('*', stars) + repeat(' ', 5 - stars + 3) + ' ' + item.mod + ' (' + item.rps + ' rps)\n'; - }, ''); -}; \ No newline at end of file diff --git a/bench/lib/utils.js b/bench/lib/utils.js new file mode 100644 index 0000000..dbbc09f --- /dev/null +++ b/bench/lib/utils.js @@ -0,0 +1,9 @@ +exports.resolve = require('path').resolve + +exports.version = function (name) { + if (name.match(/^buffet/)) { + return require(exports.resolve(__dirname, '../../package')).version; + } + + return require(exports.resolve(__dirname, '../package')).dependencies[name]; +}; \ No newline at end of file diff --git a/bench/lib/version.js b/bench/lib/version.js deleted file mode 100644 index 44812c8..0000000 --- a/bench/lib/version.js +++ /dev/null @@ -1,27 +0,0 @@ -var pkgInfo = require('../package') - , exec = require('child_process').exec - -module.exports = function (mod, cb) { - var modVersion = pkgInfo.dependencies[mod]; - if (modVersion) { - cb(null, modVersion); - } - else if (mod.match(/^buffet/)) { - cb(null, require('../../package').version); - } - else if (mod === 'varnish') { - exec('varnishd -V', function (err, stdout, stderr) { - if (err) return cb(err); - var match = stderr.match(/varnish\-([\d\.]+)/); - if (!match) { - cb(new Error('could not parse varnishd version!')); - } - else { - cb(null, match[1]); - } - }); - } - else { - cb(new Error('module not found in dependencies: ' + mod)); - } -}; \ No newline at end of file diff --git a/bench/middleware/buffet-server.js b/bench/middleware/buffet-server.js deleted file mode 100644 index 4b46e75..0000000 --- a/bench/middleware/buffet-server.js +++ /dev/null @@ -1,17 +0,0 @@ -var execFile = require('child_process').execFile - -module.exports = function (options, cb) { - var port = randomPort() - , buffetRoot = require('path').resolve(__dirname, '../..') - , buffet = execFile(buffetRoot + '/bin/buffet.js', ['-p', port, '--no-log'], {cwd: options.root}) - - buffet.stderr.on('data', function (chunk) { - if (chunk.toString().match(/listening/)) { - cb(null, port); - } - }); -}; - -function randomPort () { - return Math.round((Math.random() * 2e4) + 2e4); -} \ No newline at end of file diff --git a/bench/middleware/buffet.js b/bench/middleware/buffet.js deleted file mode 100644 index 6be0918..0000000 --- a/bench/middleware/buffet.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function (options, cb) { - return require('../../')(options.root); -}; \ No newline at end of file diff --git a/bench/middleware/ecstatic.js b/bench/middleware/ecstatic.js deleted file mode 100644 index 038b57e..0000000 --- a/bench/middleware/ecstatic.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function (options, cb) { - return require('ecstatic')(options.root); -}; \ No newline at end of file diff --git a/bench/middleware/node-static.js b/bench/middleware/node-static.js deleted file mode 100644 index 55f56cd..0000000 --- a/bench/middleware/node-static.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function (options, cb) { - var nodeStatic = require('node-static') - , fileServer = new(nodeStatic.Server)(options.root) - - return fileServer.serve.bind(fileServer); -}; \ No newline at end of file diff --git a/bench/middleware/paperboy.js b/bench/middleware/paperboy.js deleted file mode 100644 index 48b485f..0000000 --- a/bench/middleware/paperboy.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function (options, cb) { - var paperboy = require('paperboy'); - return function (req, res, next) { - paperboy.deliver(options.root, req, res); - }; -}; \ No newline at end of file diff --git a/bench/middleware/send.js b/bench/middleware/send.js deleted file mode 100644 index 66b595a..0000000 --- a/bench/middleware/send.js +++ /dev/null @@ -1,9 +0,0 @@ -var send = require('send'); - -module.exports = function (options, cb) { - return function (req, res, next) { - send(req, req.url) - .root(options.root) - .pipe(res); - }; -}; \ No newline at end of file diff --git a/bench/middleware/varnish.js b/bench/middleware/varnish.js deleted file mode 100644 index 1d9e4fa..0000000 --- a/bench/middleware/varnish.js +++ /dev/null @@ -1,20 +0,0 @@ -var spawn = require('child_process').spawn - , execFile = require('child_process').execFile - -module.exports = function (options, cb) { - var buffetPort = randomPort() - , buffetRoot = require('path').resolve(__dirname, '../..') - , buffet = execFile(buffetRoot + '/bin/buffet.js', ['-p', buffetPort], {cwd: options.root}) - , port = randomPort() - , varnish = spawn('varnishd', ['-F', '-n', require('idgen')(), '-s', 'malloc', '-b', '127.0.0.1:' + buffetPort, '-a', '127.0.0.1:' + port]) - - varnish.stderr.on('data', function (chunk) { - if (chunk.toString().match(/Child starts/)) { - cb(null, port); - } - }); -}; - -function randomPort () { - return Math.round((Math.random() * 2e4) + 2e4); -} \ No newline at end of file diff --git a/bench/node-static.js b/bench/node-static.js new file mode 100644 index 0000000..6672d44 --- /dev/null +++ b/bench/node-static.js @@ -0,0 +1,11 @@ +var utils = require('./lib/utils') + +exports.name = 'node-static'; +exports.version = utils.version(exports.name); + +exports.middleware = function (options) { + var nodeStatic = require('node-static') + , fileServer = new(nodeStatic.Server)(options.root) + + return fileServer.serve.bind(fileServer); +}; \ No newline at end of file diff --git a/bench/opts.json b/bench/opts.json new file mode 100644 index 0000000..8186031 --- /dev/null +++ b/bench/opts.json @@ -0,0 +1,3 @@ +{ + "root": "./test/files" +} \ No newline at end of file diff --git a/bench/package.json b/bench/package.json index b095f0d..c40e0ed 100644 --- a/bench/package.json +++ b/bench/package.json @@ -2,13 +2,9 @@ "name": "buffet-benchmarks", "version": "0.0.0", "dependencies": { - "idgen": "~1.1.1", "ecstatic": "~0.1.6", "node-static": "~0.6.0", - "middler": "~0.4.5", "paperboy": "~0.0.5", - "send": "~0.0.4", - "glob": "~3.1.12", - "async": "~0.1.22" + "send": "~0.0.4" } -} +} \ No newline at end of file diff --git a/bench/paperboy.js b/bench/paperboy.js new file mode 100644 index 0000000..fb82985 --- /dev/null +++ b/bench/paperboy.js @@ -0,0 +1,11 @@ +var utils = require('./lib/utils') + +exports.name = 'paperboy'; +exports.version = utils.version(exports.name); + +exports.middleware = function (options) { + var paperboy = require('paperboy'); + return function (req, res, next) { + paperboy.deliver(options.root, req, res); + }; +}; \ No newline at end of file diff --git a/bench/send.js b/bench/send.js new file mode 100644 index 0000000..4b2fffe --- /dev/null +++ b/bench/send.js @@ -0,0 +1,13 @@ +var utils = require('./lib/utils') + +exports.name = 'buffet-server'; +exports.version = utils.version(exports.name); + +exports.middleware = function (options, cb) { + var send = require('send'); + return function (req, res, next) { + send(req, req.url) + .root(options.root) + .pipe(res); + }; +}; \ No newline at end of file diff --git a/bench/varnish.js b/bench/varnish.js new file mode 100644 index 0000000..1675e7d --- /dev/null +++ b/bench/varnish.js @@ -0,0 +1,31 @@ +var spawn = require('child_process').spawn + , execFile = require('child_process').execFile + , utils = require('./lib/utils') + , buffet + , varnish + +exports.name = 'varnish'; + +exports.listen = function (options, cb) { + var buffetPort = randomPort() + , buffetRoot = utils.resolve(__dirname, '..') + , port = randomPort() + + buffet = execFile(buffetRoot + '/bin/buffet.js', ['-p', buffetPort], {cwd: options.root}); + + varnish = spawn('varnishd', ['-F', '-n', require('idgen')(), '-s', 'malloc', '-b', '127.0.0.1:' + buffetPort, '-a', '127.0.0.1:' + port]); + varnish.stderr.on('data', function (chunk) { + if (chunk.toString().match(/Child starts/)) { + cb(null, port); + } + }); +}; + +exports.close = function () { + varnish.kill(); + buffet.kill(); +}; + +function randomPort () { + return Math.round((Math.random() * 2e4) + 2e4); +} \ No newline at end of file diff --git a/package.json b/package.json index 8d0f091..86c99b4 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "mocha": "*", "idgen": "1.x", "rimraf": "2.x", - "ncp": "~0.2.6" + "ncp": "~0.2.6", + "benchmarx": "~0.1.0" }, "optionalDependencies": {}, "engines": {