From b1e0b4251bf252042623c8cd1c27daf5d2f66271 Mon Sep 17 00:00:00 2001 From: Ben Bangert <100193+bbangert@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:30:00 -0800 Subject: [PATCH] feat: add rate limit scaling to delete script Because: * We want to auto-scale our queueing. This commit: * Adds a scaling policy to the delete script. --- .../scripts/delete-unverified-accounts.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/fxa-auth-server/scripts/delete-unverified-accounts.ts b/packages/fxa-auth-server/scripts/delete-unverified-accounts.ts index 4c21b7c7d17..f6ce09da62d 100644 --- a/packages/fxa-auth-server/scripts/delete-unverified-accounts.ts +++ b/packages/fxa-auth-server/scripts/delete-unverified-accounts.ts @@ -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({