fix: increase usage query throttle to 1-2s random delay

Widen the per-group delay between Anthropic usage API calls from
1-1.5s to 1-2s to avoid upstream 429 rate limiting when multiple
accounts share the same proxy exit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erio
2026-03-07 12:53:28 +08:00
co-authored by Claude Opus 4.6
parent 1864f41f33
commit 12f61daca4
2 changed files with 5 additions and 5 deletions
@@ -20,11 +20,11 @@ describe('usageLoadQueue', () => {
await Promise.all([p1, p2, p3])
expect(timestamps).toHaveLength(3)
// 随机 1-1.5s 间隔,至少 950ms(留一点误差)
// 随机 1-2s 间隔,至少 950ms(留一点误差)
expect(timestamps[1] - timestamps[0]).toBeGreaterThanOrEqual(950)
expect(timestamps[1] - timestamps[0]).toBeLessThan(1600)
expect(timestamps[1] - timestamps[0]).toBeLessThan(2100)
expect(timestamps[2] - timestamps[1]).toBeGreaterThanOrEqual(950)
expect(timestamps[2] - timestamps[1]).toBeLessThan(1600)
expect(timestamps[2] - timestamps[1]).toBeLessThan(2100)
})
it('不同组请求并行执行', async () => {
+2 -2
View File
@@ -9,7 +9,7 @@
*/
const GROUP_DELAY_MIN_MS = 1000
const GROUP_DELAY_MAX_MS = 1500
const GROUP_DELAY_MAX_MS = 2000
type Task<T> = {
fn: () => Promise<T>
@@ -37,7 +37,7 @@ async function drain(groupKey: string) {
} catch (err) {
task.reject(err)
}
// Wait a random 1–1.5s before next request in the same group
// Wait a random 1–2s before next request in the same group
if (queue.length > 0) {
const jitter = GROUP_DELAY_MIN_MS + Math.random() * (GROUP_DELAY_MAX_MS - GROUP_DELAY_MIN_MS)
await new Promise((r) => setTimeout(r, jitter))