@zukhruf/pool 0.6.13 → 0.6.14
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 +22 -7
- package/dist/climbing.d.ts +2 -1
- package/dist/climbing.d.ts.map +1 -1
- package/dist/climbing.js +102 -22
- package/dist/climbing.js.map +1 -1
- package/dist/gradient.d.ts +2 -1
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +15 -7
- package/dist/gradient.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -37,14 +37,21 @@ The pool waits for `ready()` with no time limit. Thus, if the warm-up of a worke
|
|
|
37
37
|
|
|
38
38
|
## Choose how many workers run
|
|
39
39
|
|
|
40
|
-
| Sizing | Runs
|
|
41
|
-
| ----------------------------------- |
|
|
42
|
-
| `Fixed(n)` | n workers
|
|
43
|
-
| `Resources({ memoryPerWorker })` | one for each CPU, while each finds its memory free
|
|
44
|
-
| `HillClimbing({ memoryPerWorker })` | two first,
|
|
45
|
-
| `Gradient({ memoryPerWorker })` | two first,
|
|
40
|
+
| Sizing | Runs |
|
|
41
|
+
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
42
|
+
| `Fixed(n)` | n workers |
|
|
43
|
+
| `Resources({ memoryPerWorker })` | one for each CPU, while each finds its memory free |
|
|
44
|
+
| `HillClimbing({ memoryPerWorker })` | two first, then as many as add at least a tenth more jobs a second each (as the .NET thread pool) |
|
|
45
|
+
| `Gradient({ memoryPerWorker })` | two first, then as many as keep a job at most half again the time it takes with two (as Netflix concurrency-limits) |
|
|
46
46
|
|
|
47
|
-
The two sizings that learn
|
|
47
|
+
The two sizings that learn take steps for as long as the pool runs. A step measures three windows of at least 20 jobs and 2 seconds: at the size it has, at the size it tries, and at the size it has again. A sizing measures only while jobs wait and every worker is ready.
|
|
48
|
+
|
|
49
|
+
- A step tries one more worker, or fewer: `HillClimbing` one fewer, `Gradient` two. A step with fewer keeps every worker alive, so it costs no warm-up.
|
|
50
|
+
- The sizing keeps one more worker as soon as one step shows that it pays. It lets a worker go only after two steps in a row show that the worker does not pay.
|
|
51
|
+
- After a step that changes nothing, the sizing pauses: one window first, then twice as long after each such step, up to 16 windows. The length is random, so pools in other processes do not step at the same moments.
|
|
52
|
+
- After each window, the sizing reads the free memory again. When its workers do not fit, it runs fewer at once. It never runs more than the capacity when the pool was built.
|
|
53
|
+
|
|
54
|
+
See [ADR 0002](./docs/adr/0002-a-sizing-that-learns-compares-one-more-worker-between-two-windows.md) and [ADR 0007](./docs/adr/0007-a-sizing-that-learns-keeps-learning-in-steps-both-ways-and-pauses-between-steps-that-change-nothing.md).
|
|
48
55
|
|
|
49
56
|
## Choose when idle workers close
|
|
50
57
|
|
|
@@ -81,6 +88,13 @@ A worker that exited is in no count, and a slot whose worker the pool evicted is
|
|
|
81
88
|
|
|
82
89
|
A job that needs the slot of an exited worker starts a new worker. An eager startup also replaces an idle worker that exits. After an early exit (a worker that ran less than 10 minutes), the pool waits first: 1 s, then 2 s, 4 s, and so on up to 60 s for each early exit in a row. A worker that runs 10 minutes ends this back-off. A job does not wait for a back-off: its worker starts now. Kubernetes restarts a container in CrashLoopBackOff with the same rule. The pool does not count an evicted worker as an exit: it does not replace the worker and does not start a back-off. An evicted worker that ran 10 minutes ends the back-off too. See [ADR 0005](./docs/adr/0005-an-eager-pool-backs-off-before-it-replaces-a-worker-that-exited-early.md).
|
|
83
90
|
|
|
91
|
+
## Recipes
|
|
92
|
+
|
|
93
|
+
1. [Let the pool find how many workers pay](./docs/recipes/find-how-many-workers-pay.md)
|
|
94
|
+
2. [Warm a model once, then start the other workers](./docs/recipes/warm-a-model-once.md)
|
|
95
|
+
3. [Hold workers only while there is work](./docs/recipes/hold-workers-only-while-there-is-work.md)
|
|
96
|
+
4. [Test a pool on the real path](./docs/recipes/test-a-pool-on-the-real-path.md)
|
|
97
|
+
|
|
84
98
|
## Decisions
|
|
85
99
|
|
|
86
100
|
- [ADR 0001](./docs/adr/0001-startups-and-sizings-are-classes-that-a-caller-chooses.md): startups and sizings are classes that a caller chooses.
|
|
@@ -89,3 +103,4 @@ A job that needs the slot of an exited worker starts a new worker. An eager star
|
|
|
89
103
|
- [ADR 0004](./docs/adr/0004-a-pool-reports-its-stats-as-one-snapshot-of-counts.md): a pool reports its stats as one snapshot of counts.
|
|
90
104
|
- [ADR 0005](./docs/adr/0005-an-eager-pool-backs-off-before-it-replaces-a-worker-that-exited-early.md): an eager pool backs off before it replaces a worker that exited early.
|
|
91
105
|
- [ADR 0006](./docs/adr/0006-the-pool-evicts-an-idle-worker-that-its-eviction-lets-go-and-lends-an-idle-worker-first.md): the pool evicts an idle worker that its eviction lets go, and lends an idle worker first.
|
|
106
|
+
- [ADR 0007](./docs/adr/0007-a-sizing-that-learns-keeps-learning-in-steps-both-ways-and-pauses-between-steps-that-change-nothing.md): a sizing that learns keeps learning in steps both ways, and pauses between steps that change nothing.
|
package/dist/climbing.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare abstract class Climbing implements Sizing {
|
|
|
14
14
|
get kept(): number;
|
|
15
15
|
record({ started, finished, measurable }: Sample): void;
|
|
16
16
|
protected abstract measure(window: Window): number;
|
|
17
|
-
protected abstract pays(ratio: number): boolean;
|
|
17
|
+
protected abstract pays(ratio: number, larger: number, smaller: number): boolean;
|
|
18
|
+
protected fewer(size: number): number;
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=climbing.d.ts.map
|
package/dist/climbing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"climbing.d.ts","sourceRoot":"","sources":["../src/climbing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"climbing.d.ts","sourceRoot":"","sources":["../src/climbing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAalD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAkBD,8BAAsB,QAAS,YAAW,MAAM;;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAkBb,OAAO,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE;IAQhD,IAAI,OAAO,IAAI,MAAM,CAGpB;IAID,IAAI,IAAI,IAAI,MAAM,CAKjB;IAED,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,MAAM,GAAG,IAAI;IAgFvD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAIlD,SAAS,CAAC,QAAQ,CAAC,IAAI,CACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO;IAGV,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGtC"}
|
package/dist/climbing.js
CHANGED
|
@@ -3,41 +3,71 @@ import { capacity } from "./capacity.js";
|
|
|
3
3
|
// decide alone.
|
|
4
4
|
const jobs = 20;
|
|
5
5
|
const span = 2_000;
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// measures
|
|
6
|
+
// A pause between two steps that changed nothing doubles from one window up
|
|
7
|
+
// to this many, as .NET's hill climbing waits up to ten times longer when
|
|
8
|
+
// more threads hurt: each step with one more warms up a worker for nothing.
|
|
9
|
+
const longestPause = 16;
|
|
10
|
+
// Finds how many workers pay by trying more or fewer, step after step, for as
|
|
11
|
+
// long as the pool runs. Work that changes while it is measured, as when files
|
|
12
|
+
// arrive grouped by kind, would decide a plain before and after, so each step
|
|
13
|
+
// measures in the order A, B, A: a window at the size that pays so far, one at
|
|
14
|
+
// the size it tries, and one back at the first size. The larger of the two
|
|
15
|
+
// sizes pays when its window compared to the other passes the variant's test.
|
|
16
|
+
// One more worker that pays is kept at once; the pool lets its last worker go
|
|
17
|
+
// only after that worker failed to pay in two steps in a row, because a worker
|
|
18
|
+
// that closes too early must warm up again. A step with fewer workers keeps
|
|
19
|
+
// every worker alive. A step that changes the size leads to another step in
|
|
20
|
+
// the same direction at once; any other step turns around after a pause. The
|
|
21
|
+
// pause has a random length, so pools in other processes do not measure each
|
|
22
|
+
// other's steps (.NET; AWS's exponential backoff and jitter). Pools start with
|
|
23
|
+
// two workers and never pass what the Mac affords, which they read again after
|
|
24
|
+
// each window. Variants say what a window measures, what passes, and how many
|
|
25
|
+
// workers a step with fewer tries.
|
|
14
26
|
export class Climbing {
|
|
15
27
|
ceiling;
|
|
28
|
+
#memoryPerWorker;
|
|
29
|
+
// The workers the Mac affords now; other processes take and free memory.
|
|
30
|
+
#room;
|
|
16
31
|
#size;
|
|
32
|
+
#direction = 'more';
|
|
17
33
|
#step;
|
|
34
|
+
// Steps in a row in which fewer workers did as well.
|
|
35
|
+
#unpaid = 0;
|
|
36
|
+
// Steps in a row that changed nothing, and when the pause after them ends.
|
|
37
|
+
#calm = 0;
|
|
38
|
+
#resume = 0;
|
|
18
39
|
#before = 0;
|
|
19
|
-
#
|
|
40
|
+
#tried = 0;
|
|
20
41
|
#first = 0;
|
|
21
42
|
#count = 0;
|
|
22
43
|
#busy = 0;
|
|
23
44
|
constructor(options) {
|
|
45
|
+
this.#memoryPerWorker = options.memoryPerWorker;
|
|
24
46
|
this.ceiling = capacity(options.memoryPerWorker);
|
|
47
|
+
this.#room = this.ceiling;
|
|
25
48
|
this.#size = Math.min(2, this.ceiling);
|
|
26
|
-
this.#step = this
|
|
49
|
+
this.#step = this.ceiling > 1 ? 'before' : 'settled';
|
|
27
50
|
}
|
|
28
51
|
get current() {
|
|
29
|
-
|
|
52
|
+
if (this.#step !== 'tried')
|
|
53
|
+
return this.#size;
|
|
54
|
+
return this.#direction === 'more' ? this.#size + 1 : this.fewer(this.#size);
|
|
30
55
|
}
|
|
31
|
-
// The worker
|
|
32
|
-
// before it again.
|
|
56
|
+
// The worker a step tries stays alive while the step measures the size
|
|
57
|
+
// before it again, and a step with fewer workers keeps every worker.
|
|
33
58
|
get kept() {
|
|
34
|
-
return this.#
|
|
59
|
+
return this.#direction === 'more' &&
|
|
60
|
+
(this.#step === 'tried' || this.#step === 'after')
|
|
35
61
|
? this.#size + 1
|
|
36
62
|
: this.#size;
|
|
37
63
|
}
|
|
38
64
|
record({ started, finished, measurable }) {
|
|
39
65
|
if (this.#step === 'settled')
|
|
40
66
|
return;
|
|
67
|
+
if (this.#step === 'pause' && finished >= this.#resume) {
|
|
68
|
+
this.#step = 'before';
|
|
69
|
+
this.#restart();
|
|
70
|
+
}
|
|
41
71
|
if (!measurable) {
|
|
42
72
|
this.#restart();
|
|
43
73
|
return;
|
|
@@ -54,24 +84,74 @@ export class Climbing {
|
|
|
54
84
|
busy: this.#busy,
|
|
55
85
|
});
|
|
56
86
|
this.#restart();
|
|
87
|
+
this.#room = Math.min(this.ceiling, capacity(this.#memoryPerWorker));
|
|
88
|
+
if (this.kept > this.#room) {
|
|
89
|
+
// Memory that other processes took does not wait for two steps.
|
|
90
|
+
this.#size = Math.min(this.#size, this.#room);
|
|
91
|
+
this.#unpaid = 0;
|
|
92
|
+
this.#direction = 'fewer';
|
|
93
|
+
this.#step = 'before';
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (this.#step === 'pause')
|
|
97
|
+
return;
|
|
57
98
|
if (this.#step === 'before') {
|
|
99
|
+
// With no step that fits, the sizing measures again.
|
|
100
|
+
if (!this.#aim())
|
|
101
|
+
return;
|
|
58
102
|
this.#before = value;
|
|
59
|
-
this.#step = '
|
|
103
|
+
this.#step = 'tried';
|
|
60
104
|
}
|
|
61
|
-
else if (this.#step === '
|
|
62
|
-
this.#
|
|
105
|
+
else if (this.#step === 'tried') {
|
|
106
|
+
this.#tried = value;
|
|
63
107
|
this.#step = 'after';
|
|
64
108
|
}
|
|
65
|
-
else if (this.pays(this.#more / ((this.#before + value) / 2))) {
|
|
66
|
-
this.#size++;
|
|
67
|
-
this.#step = this.#size < this.ceiling ? 'before' : 'settled';
|
|
68
|
-
}
|
|
69
109
|
else
|
|
70
|
-
this.#
|
|
110
|
+
this.#decide((this.#before + value) / 2, finished);
|
|
111
|
+
}
|
|
112
|
+
#decide(base, finished) {
|
|
113
|
+
const size = this.#size;
|
|
114
|
+
let changed = false;
|
|
115
|
+
if (this.#direction === 'more') {
|
|
116
|
+
changed = this.pays(this.#tried / base, size + 1, size);
|
|
117
|
+
if (changed)
|
|
118
|
+
this.#size++;
|
|
119
|
+
}
|
|
120
|
+
else if (this.pays(base / this.#tried, size, this.fewer(size)))
|
|
121
|
+
this.#unpaid = 0;
|
|
122
|
+
else if (++this.#unpaid === 2) {
|
|
123
|
+
this.#unpaid = 0;
|
|
124
|
+
this.#size--;
|
|
125
|
+
changed = true;
|
|
126
|
+
}
|
|
127
|
+
this.#step = 'before';
|
|
128
|
+
if (changed)
|
|
129
|
+
this.#calm = 0;
|
|
130
|
+
else if (this.#unpaid === 0) {
|
|
131
|
+
this.#direction = this.#direction === 'more' ? 'fewer' : 'more';
|
|
132
|
+
const windows = Math.min(2 ** this.#calm++, longestPause);
|
|
133
|
+
this.#resume = finished + span * windows * (0.5 + Math.random());
|
|
134
|
+
this.#step = 'pause';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Turns the next step to a direction that fits, and tells whether one does.
|
|
138
|
+
#aim() {
|
|
139
|
+
const fewer = this.fewer(this.#size);
|
|
140
|
+
const more = this.#size < this.#room;
|
|
141
|
+
const less = fewer >= 1 && fewer < this.#size;
|
|
142
|
+
if (!more)
|
|
143
|
+
this.#direction = 'fewer';
|
|
144
|
+
if (!less)
|
|
145
|
+
this.#direction = 'more';
|
|
146
|
+
return more || less;
|
|
71
147
|
}
|
|
72
148
|
#restart() {
|
|
73
149
|
this.#count = 0;
|
|
74
150
|
this.#busy = 0;
|
|
75
151
|
}
|
|
152
|
+
// How many workers a step with fewer tries when `size` run.
|
|
153
|
+
fewer(size) {
|
|
154
|
+
return size - 1;
|
|
155
|
+
}
|
|
76
156
|
}
|
|
77
157
|
//# sourceMappingURL=climbing.js.map
|
package/dist/climbing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"climbing.js","sourceRoot":"","sources":["../src/climbing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,6EAA6E;AAC7E,gBAAgB;AAChB,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,IAAI,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"climbing.js","sourceRoot":"","sources":["../src/climbing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,6EAA6E;AAC7E,gBAAgB;AAChB,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,IAAI,GAAG,KAAK,CAAC;AAEnB,4EAA4E;AAC5E,0EAA0E;AAC1E,4EAA4E;AAC5E,MAAM,YAAY,GAAG,EAAE,CAAC;AAWxB,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,mCAAmC;AACnC,MAAM,OAAgB,QAAQ;IACnB,OAAO,CAAS;IAChB,gBAAgB,CAAS;IAClC,yEAAyE;IACzE,KAAK,CAAS;IACd,KAAK,CAAS;IACd,UAAU,GA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AAQ;QACN,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAaD,4DAA4D;IAClD,KAAK,CAAC,IAAY;QAC1B,OAAO,IAAI,GAAG,CAAC,CAAC;IAClB,CAAC;CACF"}
|
package/dist/gradient.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Climbing, type Window } from './climbing.ts';
|
|
|
2
2
|
export declare class Gradient extends Climbing {
|
|
3
3
|
#private;
|
|
4
4
|
protected measure({ jobs, busy }: Window): number;
|
|
5
|
-
protected pays(ratio: number): boolean;
|
|
5
|
+
protected pays(ratio: number, larger: number, smaller: number): boolean;
|
|
6
|
+
protected fewer(): number;
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=gradient.d.ts.map
|
package/dist/gradient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../src/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../src/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAQtD,qBAAa,QAAS,SAAQ,QAAQ;;IAKpC,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,GAAG,MAAM;IAIjD,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;cAQpD,KAAK,IAAI,MAAM;CAGnC"}
|
package/dist/gradient.js
CHANGED
|
@@ -2,17 +2,25 @@ import { Climbing } from "./climbing.js";
|
|
|
2
2
|
// Finds how many workers pay by the time a job takes, as Netflix's
|
|
3
3
|
// concurrency-limits Gradient does: one more worker pays while a job takes at
|
|
4
4
|
// most half again the time it took with two. Past that, the workers queue for
|
|
5
|
-
// something they share.
|
|
5
|
+
// something they share. Work changes, so a step with fewer runs two workers
|
|
6
|
+
// again, as Netflix's GradientLimit and Envoy measure their base time again
|
|
7
|
+
// at their least concurrency: the time with two is then as fresh as the step.
|
|
6
8
|
export class Gradient extends Climbing {
|
|
7
|
-
|
|
9
|
+
// For each size: a job's time with that many workers, divided by its time
|
|
10
|
+
// with two, as last measured.
|
|
11
|
+
#slowdown = new Map();
|
|
8
12
|
measure({ jobs, busy }) {
|
|
9
13
|
return busy / jobs;
|
|
10
14
|
}
|
|
11
|
-
pays(ratio) {
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
-
this.#slowdown
|
|
15
|
-
|
|
15
|
+
pays(ratio, larger, smaller) {
|
|
16
|
+
if (larger <= 2)
|
|
17
|
+
return true;
|
|
18
|
+
const slowdown = (smaller <= 2 ? 1 : (this.#slowdown.get(smaller) ?? 1)) * ratio;
|
|
19
|
+
this.#slowdown.set(larger, slowdown);
|
|
20
|
+
return slowdown <= 1.5;
|
|
21
|
+
}
|
|
22
|
+
fewer() {
|
|
23
|
+
return 2;
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
26
|
//# sourceMappingURL=gradient.js.map
|
package/dist/gradient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradient.js","sourceRoot":"","sources":["../src/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AAEtD,mEAAmE;AACnE,8EAA8E;AAC9E,8EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"gradient.js","sourceRoot":"","sources":["../src/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AAEtD,mEAAmE;AACnE,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,MAAM,OAAO,QAAS,SAAQ,QAAQ;IACpC,0EAA0E;IAC1E,8BAA8B;IACrB,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAU;QACtC,OAAO,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAES,IAAI,CAAC,KAAa,EAAE,MAAc,EAAE,OAAe;QAC3D,IAAI,MAAM,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7B,MAAM,QAAQ,GACZ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QAClE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO,QAAQ,IAAI,GAAG,CAAC;IACzB,CAAC;IAEkB,KAAK;QACtB,OAAO,CAAC,CAAC;IACX,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/pool",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "Lend long-lived workers, such as native helper processes, to one job at a time: startups that decide when workers start, sizings that decide how many run, evictions that decide when an idle worker closes, and replacement of a worker that exits.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zukhruf/async": "^0.6.
|
|
44
|
+
"@zukhruf/async": "^0.6.14",
|
|
45
45
|
"p-queue": "10.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@zukhruf/testing": "^0.6.
|
|
48
|
+
"@zukhruf/testing": "^0.6.14"
|
|
49
49
|
}
|
|
50
50
|
}
|