1.0.1 • Published 10 years ago

loopbusy v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
10 years ago

Loopbusy

Middleware to send 503s and keep your server alive when it's too busy to queue more requests.

var app = express();

app
  .use(loopbusy())
  .get('/', function sendOk(req, res, next) {
    res.send('ok');
  })
  .use(function handleErrors(err, req, res, next) {
    res.status(err.status).send('err');
  });

Loopbusy uses the event-loop-lag module to determine when the event loop is piling up requests.

When lag passes a threshold, loopbusy passes 503 errors to your middleware stack so your app can stay alive for some users instead of falling over for all users.

Options

loopbusy(maxLag, pollingInterval);

Max Lag

loopbusy(500);

The maximum lag (in ms) of your event loop.

Defaults to 250.

Interval

loopbusy(null, 3000);

The polling interval (in ms) for measuring your event loop. Shorter values catch business faster at the cost of additional overhead.

Defaults to 1000.

Tests

npm test