mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
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:
@@ -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 () => {
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user