Skip to content
Roman edited this page Oct 30, 2021 · 11 revisions

RateLimiterMemory

It manages limits in current process memory. It expires limited keys by setTimeout. Works in browser as well.

Note: the maximum duration, blockDuration and rateLimiter.block(key, secDuration) for memory limiter is 2147483 seconds or about 24 days because of setTimeout limitation.

const { RateLimiterMemory } = require('rate-limiter-flexible');
const rateLimiter = new RateLimiterMemory({
  points: 6,
  duration: 1,
});
    
rateLimiter.consume(key, 2) // Consume 2 points
  .then((rateLimiterRes) => {
    // Allowed
  })
  .catch((rej) => {
    // Blocked
  });   
    

See all options here

Heap snapshot statistic on high traffic

Heap snapshot Memory

Clone this wiki locally