Skip to content

Commit

Permalink
Merge pull request #16536 from mozilla/feat/delete-task-autoscaling
Browse files Browse the repository at this point in the history
feat: add rate limit scaling to delete script
  • Loading branch information
bbangert authored Mar 8, 2024
2 parents 96f6e97 + b1e0b42 commit 2f65420
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/fxa-auth-server/scripts/delete-unverified-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,23 @@ const init = async () => {
return 0;
}

const queue = new PQueue({ interval: 1000, intervalCap: taskLimit });
// Scaling suggestion is 500/5/50 rule, may start at 500/sec, and increase every 5 minutes by 50%.
// They also note increased latency may occur past 1000/sec, so we stop increasing as we approach that.
const scaleUpIntervalMins = 6;
let lastScaleUp = Date.now();
let rateLimit = taskLimit;
let queue = new PQueue({ interval: 1000, intervalCap: rateLimit });

for (const x of accounts) {
if (
rateLimit < 950 &&
Date.now() - lastScaleUp > scaleUpIntervalMins * 60 * 1000
) {
await queue.onIdle();
lastScaleUp = Date.now();
rateLimit = Math.floor(rateLimit * 1.5);
queue = new PQueue({ interval: 1000, intervalCap: rateLimit });
}
queue.add(async () => {
try {
const result = await accountDeleteManager.enqueue({
Expand Down

0 comments on commit 2f65420

Please sign in to comment.