Skip to content

Refactor delete requests to use rate limiter - #1

Open
sebtoombs wants to merge 2 commits into
mainfrom
rate-limit-requests
Open

Refactor delete requests to use rate limiter#1
sebtoombs wants to merge 2 commits into
mainfrom
rate-limit-requests

Conversation

@sebtoombs

Copy link
Copy Markdown

What

Rate limit delete requests (why) to avoid getting rate limit banned

How

Using rate-limiter-flexible with an in memory queue to limit requests. This allows us to tell Node to fire all our requests in parallel and then rely on the queue to handle meeting the rate limit requirement.

What this means is we can fire off as many requests as possible as quickly as possible (possibly taking advantage of multiple threads) until we hit the rate limit and backoff.

The rate limiter config (index.js lines 9 - 16) needs to be set, or come from come config maybe? Currently (as an example) it is set as max. 1 request (points) per 2 seconds (duration). And requests beyond that will get added to the queue (maxQueueSize 100). If the queue overflows, these requests will return an error, same as if the request had failed (but message something like "Queue is full"). There's probably no limit on the queue size (beyond the max integer in Node & memory on the runner), so could probably up that to some ridiculous value.

Note

  • Although I added a node_module dep, I didn't check in the files because I wanted to keep the PR neat, so if you want to stick with checking in the deps will need to do another npm install and then commit that.
  • We can avoid checking all the deps by bundling all the actual deps at build time (happy to add that if you want)

Comment thread index.js Outdated
}
}
// Only delete releases after the number to keep
const releasesToPurge = appReleases.slice(0, -toKeep);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this slice keep the head of the array or the tail? We want to keep the head (as these are the latest versions).

@sebtoombs sebtoombs Sep 13, 2022

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this will remove the last toKeep items from the array - which I have just realised is incorrect. Pushed a change 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants