buffet

Performance-oriented static file server for Node.js

View the Project on GitHub carlos8f/node-buffet

Idea

Serving static files should be the most efficient thing that a Node.js app can do. Turns out, runtime syscalls to the filesystem can really hang your page loads, especially if your filesystem is networked or unreliable in some other way.

Buffet takes a fully-bufferred approach -- all files are fully loaded into memory when your app boots, so you will never feel the burn of the filesystem. In practice, this is immensely efficient. So much so that putting Varnish in front of your app might even make it slower! Well, almost (summary from buffet's make bench):

****************  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 a pain, so consider using Buffet -- your pages will always be fresh and zesty!

Usage

Middleware

Middleware version (compatible with connect, union/flatiron, middler, etc.)

Install in your project with npm:

$ npm install --save buffet

Example with connect:

var connect = require('connect')
  , app = connect()
  , buffet = require('buffet')() // root defaults to ./public

app.use(buffet);
app.use(buffet.notFound);

var server = require('http').createServer(app);
server.listen(3000, function () {
  console.log('test server running on port 3000');
});

Easy built-in server

$ npm install -g buffet
$ cd /var/www/html && buffet
buffet 0.4.0 listening on port 8080

As a request handler

var server = require('http').createServer();
var buffet = require('buffet')(); // root defaults to ./public

server.on('request', buffet);
server.on('request', buffet.notFound);

server.listen(3000, function () {
  console.log('test server running on port 3000');
});

Options

Running your own benchmark

Type make bench in the buffet directory (you'll need siege installed).

Brought to you by benchmarx.

See here for my results.


Developed by Terra Eclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Aptos, CA and Washington, D.C.


License: MIT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.