@nxtedition/scheduler 4.1.11 → 4.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -10
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/limiter.d.ts +21 -0
- package/lib/limiter.d.ts.map +1 -1
- package/lib/limiter.js +266 -48
- package/lib/limiter.js.map +1 -1
- package/lib/queue.d.ts +4 -0
- package/lib/queue.d.ts.map +1 -1
- package/lib/queue.js +55 -42
- package/lib/queue.js.map +1 -1
- package/lib/scheduler.d.ts +28 -0
- package/lib/scheduler.d.ts.map +1 -1
- package/lib/scheduler.js +568 -28
- package/lib/scheduler.js.map +1 -1
- package/package.json +4 -4
package/lib/limiter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'node:stream';
|
|
2
|
+
import { types } from 'node:util';
|
|
2
3
|
import { FastQueue, NO_LIMITS, parsePriority, Queue } from "./queue.js";
|
|
3
4
|
const LIMIT_INDEX = 0;
|
|
4
5
|
const TOKENS_INDEX = 16; // separate cache line to avoid false sharing
|
|
@@ -10,6 +11,16 @@ const LIMITER_MAGIC = 0x4c494d54; // ASCII "LIMT" — sanity-check sentinel writ
|
|
|
10
11
|
// value on store and silently breaks the bucket (it can never accrue), so reject it up
|
|
11
12
|
// front rather than fail mysteriously at runtime.
|
|
12
13
|
const MAX_TOKENS = 0x7fffffff; // 2_147_483_647
|
|
14
|
+
// Anti-starvation: a queue whose front item has sat undispatched for this many
|
|
15
|
+
// consecutive timer ticks (~1s at the 100ms cadence) is force-admitted into token
|
|
16
|
+
// debt. Without this, any front item larger than the instantaneous token balance
|
|
17
|
+
// starves indefinitely under saturation — the fallback scan spends every tick's
|
|
18
|
+
// fresh credit on smaller items from other queues, so the balance never reaches the
|
|
19
|
+
// big item (measured: a 600-of-1000-capacity item never ran during 5s of competing
|
|
20
|
+
// 100-byte traffic). The resulting negative balance throttles subsequent dispatches
|
|
21
|
+
// until the debt is repaid, so long-run rate conformance is preserved; the trade-off
|
|
22
|
+
// is a transient burst of at most one stalled front per queue per ~1s.
|
|
23
|
+
const STALL_TICKS = 10;
|
|
13
24
|
function validateRate(tokensPerSecond) {
|
|
14
25
|
if (tokensPerSecond == null ||
|
|
15
26
|
!Number.isInteger(tokensPerSecond) ||
|
|
@@ -21,6 +32,19 @@ function validateRate(tokensPerSecond) {
|
|
|
21
32
|
}
|
|
22
33
|
export class Limiter extends Queue {
|
|
23
34
|
stateView;
|
|
35
|
+
// True when stateView is backed by a SharedArrayBuffer (cross-worker bucket).
|
|
36
|
+
// Non-shared limiters are single-threaded, so the hot token decrement can use a
|
|
37
|
+
// plain write instead of a lock-prefixed Atomics RMW. Cold paths (#refill credit,
|
|
38
|
+
// force-through) keep Atomics unconditionally for simplicity.
|
|
39
|
+
#shared;
|
|
40
|
+
// Set by child(): a child Limiter applies its own (typically smaller) rate ON TOP of
|
|
41
|
+
// this parent's bucket. Every consume through the child is gated by — and debited from
|
|
42
|
+
// — both buckets, so a shared parent + per-worker child gives "global rate X, per-worker
|
|
43
|
+
// rate Y". Children only ever READ the parent reference here; the parent is unaware of
|
|
44
|
+
// its children (no list, no driving) — a child's own 100ms refill timer re-checks the
|
|
45
|
+
// parent bucket, so a child task blocked on parent tokens dispatches within a tick of
|
|
46
|
+
// them accruing. Children may be nested arbitrarily.
|
|
47
|
+
#parent = null;
|
|
24
48
|
pending = 0;
|
|
25
49
|
#refillTimer;
|
|
26
50
|
// True while #refillTimer is scheduled to fire. Without this guard every #refill
|
|
@@ -29,6 +53,16 @@ export class Limiter extends Queue {
|
|
|
29
53
|
// postpones the deadline — under sustained consume() traffic the timer would
|
|
30
54
|
// never fire at its intended 100ms cadence.
|
|
31
55
|
#timerArmed = true;
|
|
56
|
+
// True while #refillTimer is ref'd (holding the event loop open). While pending > 0
|
|
57
|
+
// the timer is the ONLY thing that will ever service the queue, so it must keep the
|
|
58
|
+
// process alive — an unref'd timer let scripts exit mid-backlog with queued
|
|
59
|
+
// callbacks silently dropped (the README pipeline example truncated its output).
|
|
60
|
+
// When the queue is empty the timer is unref'd again so an idle limiter never
|
|
61
|
+
// pins the process.
|
|
62
|
+
#timerReffed = false;
|
|
63
|
+
// True when some queue's stall counter crossed STALL_TICKS at the last timer tick.
|
|
64
|
+
// Lets the drain loop skip the per-iteration stalled-queue scan in the common case.
|
|
65
|
+
#hasStalled = false;
|
|
32
66
|
static makeSharedState(tokensPerSecond) {
|
|
33
67
|
validateRate(tokensPerSecond);
|
|
34
68
|
const stateBuffer = new SharedArrayBuffer(192); // 3 cache lines, one per field
|
|
@@ -47,9 +81,35 @@ export class Limiter extends Queue {
|
|
|
47
81
|
get tokensPerSecond() {
|
|
48
82
|
return this.stateView[LIMIT_INDEX];
|
|
49
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a child Limiter that enforces an ADDITIONAL token-rate limit on top of this
|
|
86
|
+
* (the parent). A consume of N tokens through the child runs only when N tokens are
|
|
87
|
+
* available in BOTH the child's own bucket AND the parent chain's bucket(s), and the N
|
|
88
|
+
* tokens are debited from every level.
|
|
89
|
+
*
|
|
90
|
+
* Canonical use: a shared parent caps the aggregate rate (e.g. 16 MB/s across the whole
|
|
91
|
+
* process) while each worker uses a local child to cap its own share (e.g. 4 MB/s):
|
|
92
|
+
*
|
|
93
|
+
* const parent = new Limiter(Limiter.makeSharedState(16_000_000)) // global rate
|
|
94
|
+
* const out = parent.child({ tokensPerSecond: 4_000_000 }) // this worker's rate
|
|
95
|
+
* out.consume(() => send(chunk), chunk.length, 'high')
|
|
96
|
+
*
|
|
97
|
+
* `opts` mirrors the constructor's options. Priorities, streaming, and the ~1s
|
|
98
|
+
* anti-starvation force-through all work as usual and apply per level (a forced item is
|
|
99
|
+
* debited into debt on the whole chain). The child has its own refill timer; the parent
|
|
100
|
+
* needs no knowledge of its children.
|
|
101
|
+
*/
|
|
102
|
+
child(opts) {
|
|
103
|
+
const c = new Limiter(opts);
|
|
104
|
+
c.#parent = this;
|
|
105
|
+
return c;
|
|
106
|
+
}
|
|
50
107
|
constructor(opts) {
|
|
51
108
|
super();
|
|
52
|
-
|
|
109
|
+
// util.types.isSharedArrayBuffer instead of instanceof: a SAB from another realm
|
|
110
|
+
// (vm context, jest sandbox) fails instanceof and would fall through to the
|
|
111
|
+
// options branch with a misleading 'Invalid tokensPerSecond' error.
|
|
112
|
+
if (types.isSharedArrayBuffer(opts)) {
|
|
53
113
|
if (opts.byteLength !== 192) {
|
|
54
114
|
throw new Error('Invalid SharedArrayBuffer size');
|
|
55
115
|
}
|
|
@@ -57,18 +117,23 @@ export class Limiter extends Queue {
|
|
|
57
117
|
throw new Error('Invalid SharedArrayBuffer: not created by Limiter.makeSharedState');
|
|
58
118
|
}
|
|
59
119
|
this.stateView = new Int32Array(opts);
|
|
120
|
+
this.#shared = true;
|
|
60
121
|
}
|
|
61
122
|
else {
|
|
62
123
|
const tokensPerSecond = validateRate(opts?.tokensPerSecond);
|
|
63
124
|
this.stateView = new Int32Array(64);
|
|
64
125
|
Atomics.store(this.stateView, LIMIT_INDEX, tokensPerSecond);
|
|
126
|
+
this.#shared = false;
|
|
65
127
|
}
|
|
66
128
|
this.#refillTimer = setTimeout(() => {
|
|
67
129
|
this.#timerArmed = false;
|
|
68
|
-
this.#refill();
|
|
130
|
+
this.#refill(true);
|
|
69
131
|
}, 100).unref();
|
|
70
132
|
}
|
|
71
133
|
stream(priority = Queue.NORMAL, options) {
|
|
134
|
+
// Parse once per stream instead of per chunk — consume() takes the cheap
|
|
135
|
+
// numeric path for an already-parsed priority.
|
|
136
|
+
const p = parsePriority(priority);
|
|
72
137
|
return new Transform({
|
|
73
138
|
...options,
|
|
74
139
|
// `chunk` is typed `unknown`, not `Buffer`: in object mode it can be any value —
|
|
@@ -81,13 +146,24 @@ export class Limiter extends Queue {
|
|
|
81
146
|
// this callback later is harmless — a destroyed Transform drops the push, no `data`.
|
|
82
147
|
transform: (chunk, _encoding, callback) => {
|
|
83
148
|
const len = chunk?.length;
|
|
84
|
-
|
|
149
|
+
// Clamp to MAX_TOKENS: a (pathological) length above the Int32 bound must not
|
|
150
|
+
// make consume() throw synchronously out of transform and wedge the stream.
|
|
151
|
+
const bytes = typeof len === 'number' && Number.isInteger(len) && len >= 0
|
|
152
|
+
? len <= MAX_TOKENS
|
|
153
|
+
? len
|
|
154
|
+
: MAX_TOKENS
|
|
155
|
+
: 0;
|
|
85
156
|
// eslint-disable-next-line typescript-eslint/no-unsafe-argument
|
|
86
|
-
this.consume((chunk) => callback(null, chunk), bytes,
|
|
157
|
+
this.consume((chunk) => callback(null, chunk), bytes, p, chunk);
|
|
87
158
|
},
|
|
88
159
|
});
|
|
89
160
|
}
|
|
90
161
|
consume(fn, bytes, priority = Queue.NORMAL, opaque) {
|
|
162
|
+
if (typeof fn !== 'function') {
|
|
163
|
+
// Validate up front: a queued non-function would otherwise detonate later
|
|
164
|
+
// inside the drain loop, surfacing as an unattributable deferred error.
|
|
165
|
+
throw new Error('Invalid fn');
|
|
166
|
+
}
|
|
91
167
|
// bytes must be a non-negative Int32 integer: it is applied to Atomics.sub on an
|
|
92
168
|
// Int32Array, so a negative value (or one that wraps past the Int32 max) *adds*
|
|
93
169
|
// tokens — corrupting the shared bucket for every worker — and NaN/Infinity can never
|
|
@@ -99,15 +175,31 @@ export class Limiter extends Queue {
|
|
|
99
175
|
if (priority == null) {
|
|
100
176
|
priority = Queue.NORMAL;
|
|
101
177
|
}
|
|
102
|
-
if (this.pending === 0
|
|
103
|
-
|
|
104
|
-
|
|
178
|
+
if (this.pending === 0) {
|
|
179
|
+
if (this.#tryConsumeTokens(bytes)) {
|
|
180
|
+
fn(opaque);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
// The stored balance is stale until a refill credits elapsed time — without
|
|
184
|
+
// this, the first consume on a fresh/idle limiter always queued (and then ran
|
|
185
|
+
// synchronously from the queued-path #refill below while still returning
|
|
186
|
+
// false, breaking the documented "true if fn ran immediately" contract).
|
|
187
|
+
// With pending === 0 the refill's drain loop is a no-op, so this only
|
|
188
|
+
// advances the clock; ordering is unaffected.
|
|
189
|
+
this.#refill();
|
|
190
|
+
if (this.#tryConsumeTokens(bytes)) {
|
|
191
|
+
fn(opaque);
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
105
194
|
}
|
|
106
195
|
const p = parsePriority(priority);
|
|
107
196
|
const queue = this.queues[p + 3];
|
|
108
197
|
this.pending += 1;
|
|
109
198
|
queue.arr.push(fn, bytes, opaque);
|
|
110
199
|
queue.cnt += 1;
|
|
200
|
+
if (queue.cnt === 1) {
|
|
201
|
+
this.nonEmptyMask |= 1 << queue.i;
|
|
202
|
+
}
|
|
111
203
|
// Only attempt a synchronous credit + drain when it can matter:
|
|
112
204
|
// - first backlog item (pending === 1): nothing has attempted a drain for it
|
|
113
205
|
// yet, and tokens may have accrued since the last refill;
|
|
@@ -129,7 +221,10 @@ export class Limiter extends Queue {
|
|
|
129
221
|
if (!Number.isInteger(bytes) || bytes < 0 || bytes > MAX_TOKENS) {
|
|
130
222
|
throw new Error('Invalid bytes');
|
|
131
223
|
}
|
|
132
|
-
|
|
224
|
+
// Refill so the (chain) check sees freshly accrued tokens. For a child we refill
|
|
225
|
+
// unconditionally — our own bucket may hold enough yet the parent chain still need
|
|
226
|
+
// crediting before #tryConsumeTokens consults it.
|
|
227
|
+
if (this.#parent !== null || this.stateView[TOKENS_INDEX] < bytes) {
|
|
133
228
|
this.#refill();
|
|
134
229
|
}
|
|
135
230
|
return this.pending === 0 && this.#tryConsumeTokens(bytes);
|
|
@@ -150,23 +245,79 @@ export class Limiter extends Queue {
|
|
|
150
245
|
// oversized requests only make progress via the queued drain loop in #refill(), which
|
|
151
246
|
// forces them through into debt once the bucket is full. This keeps tryConsume() a
|
|
152
247
|
// true non-blocking poll and never grants more than the bucket can hold on the fast path.
|
|
153
|
-
|
|
248
|
+
const tokens = this.stateView[TOKENS_INDEX];
|
|
249
|
+
if (tokens < bytes) {
|
|
154
250
|
return false;
|
|
155
251
|
}
|
|
156
|
-
|
|
252
|
+
// Child (see child()): the request must also fit the parent chain's bucket(s), and
|
|
253
|
+
// is debited from every level. Check the parent FIRST (it consumes the parent
|
|
254
|
+
// chain on success); only debit our own bucket once the whole chain has granted, so
|
|
255
|
+
// a parent shortfall needs no rollback (we haven't touched our bucket yet).
|
|
256
|
+
if (this.#parent !== null && !this.#parent.#tryConsumeTokens(bytes)) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
if (this.#shared) {
|
|
260
|
+
Atomics.sub(this.stateView, TOKENS_INDEX, bytes);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Single-threaded: a plain write avoids the lock-prefixed RMW on the hottest path.
|
|
264
|
+
this.stateView[TOKENS_INDEX] = tokens - bytes;
|
|
265
|
+
}
|
|
157
266
|
return true;
|
|
158
267
|
}
|
|
159
|
-
|
|
268
|
+
// True iff some bucket in the chain BLOCKS this request (tokens < bytes) while already
|
|
269
|
+
// at capacity (tokens >= its rate) — i.e. that level can never accrue enough, so the
|
|
270
|
+
// request is oversized for it and waiting is pointless. When no blocking level is full,
|
|
271
|
+
// every shortfall is temporary and the request should wait, not force into debt. For a
|
|
272
|
+
// non-child this is exactly the old `tokens >= LIMIT` test (the caller already knows
|
|
273
|
+
// tokens < bytes from the failed scan).
|
|
274
|
+
#chainHasFullBlocker(bytes) {
|
|
275
|
+
const tok = this.stateView[TOKENS_INDEX];
|
|
276
|
+
if (tok < bytes && tok >= this.stateView[LIMIT_INDEX]) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
for (let n = this.#parent; n !== null; n = n.#parent) {
|
|
280
|
+
const t = n.stateView[TOKENS_INDEX];
|
|
281
|
+
if (t < bytes && t >= n.stateView[LIMIT_INDEX]) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
// Debit `bytes` from this bucket AND every ancestor unconditionally, driving them into
|
|
288
|
+
// debt if needed. Used by the drain loop's anti-starvation / oversized force-through so
|
|
289
|
+
// a forced item is charged to the whole chain (mirroring #tryConsumeTokens' debit), not
|
|
290
|
+
// just the local bucket. Subsequent refills repay each level's debt before it drains
|
|
291
|
+
// anything else, preserving the long-run rate at every level.
|
|
292
|
+
#forceConsume(bytes) {
|
|
293
|
+
if (this.#shared) {
|
|
294
|
+
Atomics.sub(this.stateView, TOKENS_INDEX, bytes);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
this.stateView[TOKENS_INDEX] -= bytes;
|
|
298
|
+
}
|
|
299
|
+
if (this.#parent !== null) {
|
|
300
|
+
this.#parent.#forceConsume(bytes);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Credit tokens accrued since the last refill, without draining the queue. Split out of
|
|
304
|
+
// #refill so a child can refresh its parent chain's buckets before a chain check.
|
|
305
|
+
#credit() {
|
|
160
306
|
const rate = this.tokensPerSecond;
|
|
161
307
|
const currentToken = this.stateView[TOKENS_INDEX];
|
|
162
308
|
const refillTime = this.stateView[REFILL_INDEX];
|
|
163
309
|
// performance.now() | 0 is integer ms since process start, kept in Int32 range so it
|
|
164
310
|
// matches REFILL_INDEX's Int32 storage. Date.now() (~1.74 trillion) would overflow Int32.
|
|
311
|
+
// `|| 1` wherever a value is stored as the anchor: 0 doubles as the never-anchored
|
|
312
|
+
// sentinel below, and a real clock reading of 0 (process's first ms, or the Int32
|
|
313
|
+
// wrap passing through 0) written as an anchor would re-trigger the fill-to-capacity
|
|
314
|
+
// first-refill branch on every subsequent call. A 1ms skew is far below the
|
|
315
|
+
// limiter's 100ms granularity.
|
|
165
316
|
const now = performance.now() | 0;
|
|
166
317
|
if (refillTime === 0) {
|
|
167
318
|
// First refill anchors the clock and fills the bucket to capacity. CAS so that when
|
|
168
319
|
// multiple workers race the very first refill, only one of them performs the fill.
|
|
169
|
-
if (Atomics.compareExchange(this.stateView, REFILL_INDEX, 0, now) === 0) {
|
|
320
|
+
if (Atomics.compareExchange(this.stateView, REFILL_INDEX, 0, now || 1) === 0) {
|
|
170
321
|
const fill = rate - currentToken;
|
|
171
322
|
if (fill > 0) {
|
|
172
323
|
Atomics.add(this.stateView, TOKENS_INDEX, fill);
|
|
@@ -180,7 +331,7 @@ export class Limiter extends Queue {
|
|
|
180
331
|
// Negative elapsed = the Int32 ms counter wrapped (~24.8 days); room <= 0 = the
|
|
181
332
|
// bucket is already at/over capacity (a full bucket cannot bank time). Either way,
|
|
182
333
|
// re-anchor the clock to now and drop the carried fraction without crediting.
|
|
183
|
-
Atomics.compareExchange(this.stateView, REFILL_INDEX, refillTime, now);
|
|
334
|
+
Atomics.compareExchange(this.stateView, REFILL_INDEX, refillTime, now || 1);
|
|
184
335
|
}
|
|
185
336
|
else {
|
|
186
337
|
// Tokens accrue at `rate` per 1000ms. Credit only whole tokens and advance the
|
|
@@ -198,16 +349,20 @@ export class Limiter extends Queue {
|
|
|
198
349
|
// Bucket fills this tick: clamp to capacity and snap the clock to now —
|
|
199
350
|
// overflow time cannot be banked.
|
|
200
351
|
granted = room;
|
|
201
|
-
newRefillTime = now;
|
|
352
|
+
newRefillTime = now || 1;
|
|
202
353
|
}
|
|
203
354
|
else {
|
|
204
355
|
// floor(granted * 1000 / rate) <= elapsedMs, so the clock never passes now;
|
|
205
356
|
// the un-advanced remainder (worth < one token) carries forward.
|
|
206
|
-
newRefillTime = refillTime + Math.floor((granted * 1000) / rate);
|
|
357
|
+
newRefillTime = refillTime + Math.floor((granted * 1000) / rate) || 1;
|
|
207
358
|
}
|
|
208
359
|
// Gate the credit on the REFILL CAS so concurrent refills across workers never
|
|
209
360
|
// double-count the same elapsed window: only the winner advances the clock and
|
|
210
|
-
// adds tokens.
|
|
361
|
+
// adds tokens. NB: the credit below is a separate atomic op — a worker
|
|
362
|
+
// descheduled here for >= room/rate seconds while another worker completes a
|
|
363
|
+
// full refill can transiently push tokens above capacity (bounded by `rate`,
|
|
364
|
+
// self-correcting on the next refill via the room <= 0 re-anchor). Accepted as
|
|
365
|
+
// the over-grant mirror of the documented brief-debt soft-limit race.
|
|
211
366
|
if (Atomics.compareExchange(this.stateView, REFILL_INDEX, refillTime, newRefillTime) ===
|
|
212
367
|
refillTime) {
|
|
213
368
|
Atomics.add(this.stateView, TOKENS_INDEX, granted);
|
|
@@ -217,6 +372,29 @@ export class Limiter extends Queue {
|
|
|
217
372
|
// until it is worth at least one whole token.
|
|
218
373
|
}
|
|
219
374
|
}
|
|
375
|
+
}
|
|
376
|
+
// fromTimer is true only for the 100ms cadence timer callback: stall bookkeeping
|
|
377
|
+
// ticks on the timer (not on consume-triggered drains) so its time base is real
|
|
378
|
+
// elapsed time, independent of traffic volume.
|
|
379
|
+
#refill(fromTimer = false) {
|
|
380
|
+
if (fromTimer && this.pending > 0) {
|
|
381
|
+
// A queue with items whose front didn't dispatch since the last tick is
|
|
382
|
+
// stalling (every dispatch from a queue resets its counter in the drain
|
|
383
|
+
// loop below). Crossing STALL_TICKS arms the force-through in the drain.
|
|
384
|
+
for (let p = 0; p < this.queues.length; p++) {
|
|
385
|
+
const q = this.queues[p];
|
|
386
|
+
if (q.cnt > 0 && ++q.stall >= STALL_TICKS) {
|
|
387
|
+
this.#hasStalled = true;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
this.#credit();
|
|
392
|
+
// Keep every ancestor bucket fresh too, so the chain check in #tryConsumeTokens
|
|
393
|
+
// below sees tokens accrued on the parent(s) since their last own refill. A child
|
|
394
|
+
// is gated by BOTH its own bucket and the parent chain (see child()).
|
|
395
|
+
for (let p = this.#parent; p !== null; p = p.#parent) {
|
|
396
|
+
p.#credit();
|
|
397
|
+
}
|
|
220
398
|
try {
|
|
221
399
|
// NB: this loop is intentionally NOT gated on `tokens > 0`. Weightless (0-byte)
|
|
222
400
|
// tasks always satisfy #tryConsumeTokens regardless of the token balance, so they
|
|
@@ -225,45 +403,71 @@ export class Limiter extends Queue {
|
|
|
225
403
|
// the whole debt-repayment window. When nothing else fits, the scan below returns
|
|
226
404
|
// promptly (it never force-dispatches unless the bucket is full), so this does not spin.
|
|
227
405
|
while (this.pending > 0) {
|
|
228
|
-
let queue =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
406
|
+
let queue = null;
|
|
407
|
+
// Anti-starvation force-through (see STALL_TICKS): the highest-priority queue
|
|
408
|
+
// whose front has been blocked for >= STALL_TICKS timer ticks dispatches into
|
|
409
|
+
// debt, regardless of the current balance. Without this, the fallback scan
|
|
410
|
+
// below spends every tick's fresh credit on smaller items so a large front
|
|
411
|
+
// never sees enough tokens — and an oversized (> capacity) front could only
|
|
412
|
+
// ever force through via the bucket-completely-full branch, which sustained
|
|
413
|
+
// traffic postpones indefinitely.
|
|
414
|
+
if (this.#hasStalled) {
|
|
415
|
+
this.#hasStalled = false;
|
|
238
416
|
for (let p = this.queues.length - 1; p >= 0; p--) {
|
|
239
417
|
const q = this.queues[p];
|
|
240
|
-
if (q.cnt
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
highest = q;
|
|
245
|
-
}
|
|
246
|
-
if (this.#tryConsumeTokens(q.arr[q.idx + 1])) {
|
|
418
|
+
if (q.cnt > 0 && q.stall >= STALL_TICKS) {
|
|
419
|
+
if (!this.#tryConsumeTokens(q.arr[q.idx + 1])) {
|
|
420
|
+
this.#forceConsume(q.arr[q.idx + 1]);
|
|
421
|
+
}
|
|
247
422
|
queue = q;
|
|
248
423
|
break;
|
|
249
424
|
}
|
|
250
425
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
426
|
+
}
|
|
427
|
+
if (queue == null) {
|
|
428
|
+
queue = this.getNextQueue(NO_LIMITS, 0);
|
|
429
|
+
if (queue == null || queue.cnt === 0) {
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
if (!this.#tryConsumeTokens(queue.arr[queue.idx + 1])) {
|
|
433
|
+
// The preferred queue's front task doesn't fit; scan all queues from
|
|
434
|
+
// highest to lowest priority for any task whose byte requirement fits
|
|
435
|
+
// within available tokens (starvation prevention).
|
|
436
|
+
queue = null;
|
|
437
|
+
let highest = null;
|
|
438
|
+
for (let p = this.queues.length - 1; p >= 0; p--) {
|
|
439
|
+
const q = this.queues[p];
|
|
440
|
+
if (q.cnt === 0) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (highest === null) {
|
|
444
|
+
highest = q;
|
|
445
|
+
}
|
|
446
|
+
if (this.#tryConsumeTokens(q.arr[q.idx + 1])) {
|
|
447
|
+
queue = q;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
261
450
|
}
|
|
262
|
-
|
|
263
|
-
|
|
451
|
+
if (queue == null) {
|
|
452
|
+
// Nothing fits the tokens available right now. If the bucket is already full
|
|
453
|
+
// (at capacity — it can never hold more), every remaining task is larger than
|
|
454
|
+
// the bucket can ever cover, so waiting is pointless and they would stall
|
|
455
|
+
// forever. Force the highest-priority such task through into debt; the
|
|
456
|
+
// tokens < 0 result drops out of this loop and subsequent refills repay the
|
|
457
|
+
// debt before anything else drains — the correct throttle for an over-large unit.
|
|
458
|
+
if (highest !== null &&
|
|
459
|
+
this.#chainHasFullBlocker(highest.arr[highest.idx + 1])) {
|
|
460
|
+
this.#forceConsume(highest.arr[highest.idx + 1]);
|
|
461
|
+
queue = highest;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
264
466
|
}
|
|
265
467
|
}
|
|
266
468
|
}
|
|
469
|
+
// Dispatching from a queue means its front is making progress.
|
|
470
|
+
queue.stall = 0;
|
|
267
471
|
const fn = queue.arr[queue.idx];
|
|
268
472
|
const opaque = queue.arr[queue.idx + 2];
|
|
269
473
|
queue.arr[queue.idx++] = null;
|
|
@@ -272,6 +476,7 @@ export class Limiter extends Queue {
|
|
|
272
476
|
queue.cnt -= 1;
|
|
273
477
|
this.pending -= 1;
|
|
274
478
|
if (queue.cnt === 0) {
|
|
479
|
+
this.nonEmptyMask &= ~(1 << queue.i);
|
|
275
480
|
queue.idx = 0;
|
|
276
481
|
// See scheduler.ts: `arr = []` beats `length = 0` in V8 on this hot path.
|
|
277
482
|
queue.arr = [];
|
|
@@ -297,9 +502,22 @@ export class Limiter extends Queue {
|
|
|
297
502
|
}
|
|
298
503
|
}
|
|
299
504
|
finally {
|
|
300
|
-
if (this.pending > 0
|
|
301
|
-
this.#timerArmed
|
|
302
|
-
|
|
505
|
+
if (this.pending > 0) {
|
|
506
|
+
if (!this.#timerArmed) {
|
|
507
|
+
this.#timerArmed = true;
|
|
508
|
+
this.#refillTimer.refresh();
|
|
509
|
+
}
|
|
510
|
+
// While work is queued the timer is the only thing guaranteed to service
|
|
511
|
+
// it — hold the event loop open or a script with nothing else pending
|
|
512
|
+
// exits mid-backlog, silently dropping the queued callbacks.
|
|
513
|
+
if (!this.#timerReffed) {
|
|
514
|
+
this.#timerReffed = true;
|
|
515
|
+
this.#refillTimer.ref();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
else if (this.#timerReffed) {
|
|
519
|
+
this.#timerReffed = false;
|
|
520
|
+
this.#refillTimer.unref();
|
|
303
521
|
}
|
|
304
522
|
}
|
|
305
523
|
}
|
package/lib/limiter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limiter.js","sourceRoot":"","sources":["../src/limiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAiB,MAAM,YAAY,CAAA;AAEtF,MAAM,WAAW,GAAG,CAAC,CAA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AED,IAAI,CAAC;oBACH,EAAE,CAAC,MAAM,CAAC,CAAA;gBACZ,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,uEAAuE;oBACvE,0EAA0E;oBAC1E,iEAAiE;oBACjE,4EAA4E;oBAC5E,wEAAwE;oBACxE,oDAAoD;oBACpD,cAAc,CAAC,GAAG,EAAE;wBAClB,MAAM,GAAG,CAAA;oBACX,CAAC,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACrB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;oBACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;oBACvB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAA;gBAC7B,CAAC;gBACD,yEAAyE;gBACzE,sEAAsE;gBACtE,6DAA6D;gBAC7D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;oBACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;oBACxB,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;gBACzB,CAAC;YACH,CAAC;iBAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBAC7B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;gBACzB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/lib/queue.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ export declare class FastQueue {
|
|
|
2
2
|
idx: number;
|
|
3
3
|
cnt: number;
|
|
4
4
|
arr: Array<unknown>;
|
|
5
|
+
stall: number;
|
|
6
|
+
readonly i: number;
|
|
7
|
+
constructor(i: number);
|
|
5
8
|
}
|
|
6
9
|
export type NumberPriority = -3 | -2 | -1 | 0 | 1 | 2 | 3;
|
|
7
10
|
export type Priority = NumberPriority | 'lowest' | 'lower' | 'low' | 'normal' | 'high' | 'higher' | 'highest';
|
|
@@ -16,6 +19,7 @@ export declare class Queue {
|
|
|
16
19
|
static readonly HIGHER = 2;
|
|
17
20
|
static readonly HIGHEST = 3;
|
|
18
21
|
private counter;
|
|
22
|
+
protected nonEmptyMask: number;
|
|
19
23
|
protected queues: FastQueue[];
|
|
20
24
|
protected getNextQueue(limits: number[], running: number): FastQueue | null;
|
|
21
25
|
}
|
package/lib/queue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IACpB,GAAG,SAAI;IACP,GAAG,SAAI;IACP,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAK;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IACpB,GAAG,SAAI;IACP,GAAG,SAAI;IACP,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAK;IAIxB,KAAK,SAAI;IAGT,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;gBACN,CAAC,EAAE,MAAM;CAGtB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,MAAM,QAAQ,GAChB,cAAc,GACd,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,SAAS,CAAA;AAEb,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CA8BhE;AAsBD,eAAO,MAAM,SAAS,EAAE,MAAM,EAQ7B,CAAA;AAED,qBAAa,KAAK;IAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,MAAK;IAC3B,MAAM,CAAC,QAAQ,CAAC,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