Permalink
Browse files

Merge branch 'master' of github.com:carlos8f/node-buffet

  • Loading branch information...
2 parents 43d7b1d + b799cf5 commit 6d08732eb6be6c703f870b54cb3765825de88067 Carlos Rodriguez committed Aug 29, 2012
View
@@ -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
View
@@ -19,13 +19,13 @@ In practice, this is immensely efficient. So much so that putting
slower! Well, almost (summary from buffet's `make bench`):
```
-***** varnish@3.0.2 (6816.8 rps)
-***** buffet-server@0.3.11 (6228.96 rps)
-***** buffet@0.3.11 (5457.76 rps)
-**** node-static@~0.6.0 (4135.2 rps)
-** send@~0.0.4 (2542.67 rps)
-** ecstatic@~0.1.6 (2063.1 rps)
-* paperboy@~0.0.5 (983.15 rps)
+**************** varnish (5876.03 rps)
+**************** buffet-server (5587.53 rps)
+************** buffet (5008.57 rps)
+********** node-static (3643.76 rps)
+****** send (2130.13 rps)
+***** ecstatic (1690.86 rps)
+*** paperboy (737.16 rps)
```
Continuous deployment is also becoming all the rage, and restarting Varnish is
@@ -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.
- - -
View
@@ -14,14 +14,6 @@ In the buffet root, run:
$ make bench
```
-Or to run a specific benchmark,
-
-```bash
-$ node bench <module> [time] [wait]
-```
-
-Time defaults to `30` (seconds), and `wait` to `10` (seconds) between tests.
-
My results
----------
@@ -0,0 +1,26 @@
+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, '..')
+
+ 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);
+}
View
@@ -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);
+};
View
@@ -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);
+};
View
@@ -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();
- });
- });
-});
View
@@ -1,5 +0,0 @@
-module.exports = function repeat (c, len) {
- var ret = '';
- while (ret.length < len) ret += c;
- return ret;
-};
View
@@ -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);
- });
- });
-};
View
@@ -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';
- }, '');
-};
View
@@ -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];
+};
View
@@ -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));
- }
-};
@@ -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);
-}
@@ -1,3 +0,0 @@
-module.exports = function (options, cb) {
- return require('../../')(options.root);
-};
@@ -1,3 +0,0 @@
-module.exports = function (options, cb) {
- return require('ecstatic')(options.root);
-};
@@ -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);
-};
@@ -1,6 +0,0 @@
-module.exports = function (options, cb) {
- var paperboy = require('paperboy');
- return function (req, res, next) {
- paperboy.deliver(options.root, req, res);
- };
-};
@@ -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);
- };
-};
Oops, something went wrong.

0 comments on commit 6d08732

Please sign in to comment.