millisecond throttel not working; is only trotteling up to 1 second.
Closed this issue · 4 comments
awb99 commented
I use a new RateLimiter (1, 8000) and thought this means that I want to throttle up to a frequency of
1 every 8 seconds.
However, it seems to reduce it to once every second.
I think it is important to be able to select this higher number.
jhurliman commented
Hi, thanks for the report. Do you have a snippet of runnable code that I can use to troubleshoot this with?
awb99 commented
the pings will appear in second intervals, even though I specified 8 seocnds intervals.
var RateLimiter = require('limiter').RateLimiter;
// Limit understands 'second', 'minute', 'day', or a number of milliseconds
var limiter2 = new RateLimiter(1, '8000');
function ping (i) {
limiter2.removeTokens(1, (err, remainingRequests) => {
console.log("ping.. " + i);
})
}
for (var i=0;i<100;i++) {
ping (i)
}
perryh commented
@awb99 pass in a number for your interval param e.g.
new RateLimiter(1, 8000);
If you pass '8000' it will fall out of this switch and default to 1s.
https://github.com/jhurliman/node-rate-limiter/blob/master/lib/tokenBucket.js#L20-L33