celerity

celerity uses redis to do centralized rate limiting for applications running on multiple heroku dynos

celerity

celerity uses redis to do centralized rate limiting for applications running on multiple heroku dynos (or processes).

npm install celerity

see example.js for a simple rate limited webserver using celerity

var celerity = require('celerity');
 
var redis = require('redis');
var config = {
    redis: redis.createClient(),
    timespan: 10 * 1000,
    bucketCount: 10
};

celerity keeps the rate for the last timespan milliseconds.

timespan is divided into bucketCount buckets. the rate is stored in the buckets. buckets older than timespan expire every timespan / bucketCount milliseconds.

a higher bucketCount increases the frequency and accuracy of the expires but uses more memory and results in slower read operations. if timespan is several seconds long it is usually enough to have a bucket for every second.

use the prefix property to set a prefix for all redis keys used by celerity. the default prefix is celerity:.

celerity.increment(config, 'event', 1, function(err) {
});

atomic. complexity: O(1).

celerity.read(config, 'event', function(errrate) {
});

atomic. complexity: O(n) where n is bucketCount.

celerity.incrementAndRead(config, 'event', 1, function(errrate) {
});

atomic. complexity: O(n) where n is bucketCount.