Comments (8)
@animir Sounds good - will check both of these. Thanks again for all the help and time.
from node-rate-limiter-flexible.
@vworld Yes, until you change number of points for the blocked key, it will be blocked.
from node-rate-limiter-flexible.
Sounds awesome, thank you for the support.
from node-rate-limiter-flexible.
@vworld Hi, thank you!
Unfortunately, there is no way to achieve that with a single consume
call — it overwrites the duration for the key, so it will expire based on default limiter option.
You can call get(key)
to check if key is blocked forever and if so, don't call consume
.
from node-rate-limiter-flexible.
@animir Thank you for the quick response.
I was thinking about using blacklist but the docs say Blacklisted keys are blocked on code level not in store/memory
. So I assume this will not work in a distributed system, where if a block is set in one process/node/machine it is honored by all processes/node/machine. Is that accurate?
And if we use RedisRateLimiter to block a key, the same will be propagated to redis and the block will be available across all machines that use the same key and same redis server. Is that correct?
from node-rate-limiter-flexible.
@vworld Yes, array of blocked keys stored in blackList
is accessible for the current single process only. You could store blocked keys in any store and check it with isBlackListed
function a way suitable for you. It is more work to store list of blocked keys somewhere else in database, but you could easily use Redis for that.
As of RateLimiterRedis, yes. Blocked keys are blocked on the Redis server level making it blocked for any process in distributed environment.
from node-rate-limiter-flexible.
@vworld Just another idea in addition to the answer for the first question. To store list of blocked keys you could easily store it with another instance of RateLimiterFlexible with options {points: 1, duration: 0}. If key should be blocked you can use set
method, then check it with get
method inside isBlackListed
function of RLWrapperBlackAndWhite
. But it is still one more request to the store, which shouldn't any problem though.
from node-rate-limiter-flexible.
Just a heads up - Just like you suggested, I ended up using get
to check if the key is blocked before using consume.
The assumption here is that once a key is blocked with secDuration=0
the key is blocked forever with msBeforeNext = -1
until we try to consume
the key again.
So something like this works for me while maintaining availability of the block thorough out the distributed setup. This basically goes with the paradigm of my codes that expect an error whenever a key is blocked.
/**
* Consumes the specified amount of points for a key
* @throws {RateLimiterRes} - msBeforeNext > -1 if not blocked and msBeforeNext = -1 if key is blocked
* @param {string} ip
* @param {number} pointsToConsume
* @returns {Promise<void>}
* @private
*/
private async _attemptToConsumePoints(ip: string, pointsToConsume: number = 1){
const rLKey = this._getLimiterKey(ip);
// check if key is blocked
const res = await this.rateLimiter.get(rLKey);
if (res && res.msBeforeNext === -1) {
throw res;
}
await this.rateLimiter.consume(rLKey, pointsToConsume);
}
While I have not tested the assumptions fully but initial tests look promising.
@animir is it safe to assume a blocked key will always return msBeforeNext = -1
until we consume
from node-rate-limiter-flexible.
Related Issues (20)
- Redis storing more points than inMemoryBlockOnConsumed limit HOT 9
- High response times with execEvenly: true HOT 4
- RateLimiterMongo Docs/Logic Change Needed HOT 4
- Make it possible to log when an error occurs HOT 5
- Microsoft Azure's CosmosDB MongoServerError: The 'expireAfterSeconds' option is supported on '_ts' field only HOT 3
- question: Two constraints with a single point total? HOT 2
- Use of .set() function HOT 1
- Allow passing MemoryStorage `storeClient` for RateLimiterMemory HOT 4
- limiter.removeTokens of RateLimiterQueue with maximum wait time HOT 1
- DB queries hang when using sequelize/mariadb HOT 3
- BurstyRateLimiter.get( key ) throws error when key doesn't exist yet HOT 2
- TypeError: Cannot read properties of null (reading 'points') using mongoose HOT 9
- Redis configuration
- Run test using github actions HOT 1
- Lua script takes non integer argument as input which causes random error on user supplied input HOT 6
- Lua Script uses only Write commands and Cannot Scale in a Redis Cluster HOT 9
- Rate limit redis - Express middleware HOT 7
- Unable to use table with schema name HOT 7
- Redis limiter on version 3.0.2 TypeError: Invalid argument type TypeError: result is not iterable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-rate-limiter-flexible.