Skip to content

Latest commit

 

History

History
139 lines (105 loc) · 4.87 KB

README.md

File metadata and controls

139 lines (105 loc) · 4.87 KB

buffet

Performance-oriented static file server

build status

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-html):

serving a 4k html file, siege -c 10:

****************  nginx (7653.15 rps)
****************  varnish (7323.69 rps)
***************   buffet-server (6803.9 rps)
**************    buffet (6297.18 rps)
**********        st (4338.95 rps)
*********         node-static (4050.1 rps)
********          send (3363.26 rps)
*******           paperboy (3283.29 rps)
******            ecstatic (2556.29 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.)

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

  • root: Document root. Can also be passed as the first parameter to buffet(). (Default: ./public)
  • indexes: True to look for options.index and serve it for directory requests. (Default: true)
  • index: Name of index file to look for. (Default: index.html)
  • gzip: True to enable gzip when clients can accept it. (Default: true)
  • watch: True to auto-update the buffer when files change. (Default: true)
  • poweredBy: True to add the X-Powered-By header. (Default: true)
  • maxAge: Number of max-age seconds to set Cache-Control header. Set to false or 0 to disable. (Default: 300)
  • notFoundPath: Path to be rendered on buffetMiddleware.notFound. (Default: /404.html)
  • keepAlive: Timeout (in milliseconds) for HTTP keep-alive. (Default: 5000)
  • defaultContentType: If the file does not have an extension, set this to specify the default Content-Type sent to the browser. This defaults to application/octet-stream.

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.