Rest: Support shared/external rate limit tracking.
paperclover opened this issue · 4 comments
Something that might be interesting is if you could pass some object as a rateLimitTracker
, which would be an interface that could accept, store, and return rate limit data observed by the fetcher. The idea being if you had rate limits stored on each shard of a bot (where shards are separate instances, maybe even on separate computers), you could optionally link them up using something like Redis. The idea being if all instances of a bot share the same rate limit store, it should reduce the chance of a 429 being returned during high usage.
Opt in behavior, we'd essentially refactor our rate limiting system to a MemoryRateLimitTracker
which would be the default for the rest client.
Oh, and then for purplet, we could offer this as a part of the config file, like config.rateLimitTracker
or something.
ooh, I like this
we will use https://www.npmjs.com/package/keyv for this feature nevermind, this does not support non-node environments by default. we need to find an alternative.
it should be available by 2.0 release. in the purplet framework itself, this cache can be shared with the structures cache.
code around here has to be modified to use the async key value store: https://github.com/CRBT-Team/Purplet/blob/main/packages/rest/src/Fetcher.ts#L37. shouldn't be too difficult.