2.0.1 • Published 4 years ago

leakybucket-rate-limiter v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

leakybucket

npm.io npm.io npm.io

Leaky Bucket Algorithm :

Leaky Bucket Algorithm uses a bucket or queue to hold the incoming requests. Whenever a new request arrives, it is appended to the rear of the queue, until the queue is not full.

The requests are processed at fixed time intervals in the first come first serve (FCFS) manner, i.e. old requests are the one to be executed first. If the queue is full, the remaining are dropped or leaked with a proper message or notification to the client.

Usage

const express = require('express');
const app = express();
const { rateLimiter } = require('leakybucket-rate-limiter');

const concurrentRequests = 5;
const queueLengthLimit = 15;

app.use(rateLimiter(concurrentRequests, queueLengthLimit));

// By default concurrentRequests = 1 and queueLengthLimit = 2

app.get('/', (req, res) => {
  res.json({ msg: 'AoK' });
});

app.listen(5000, () => {
  console.log('Server setup on PORT', 5000);
});