@oneuptime/common 11.3.22 → 11.3.23
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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default class EventLoop {
|
|
2
|
+
/**
|
|
3
|
+
* Yields control back to the Node.js event loop, resuming on a later
|
|
4
|
+
* "check" phase tick.
|
|
5
|
+
*
|
|
6
|
+
* Use this to break up CPU-bound synchronous work — e.g. transforming
|
|
7
|
+
* tens of thousands of OTLP datapoints / spans / log records inside a
|
|
8
|
+
* single ingest job — so the process can service pending I/O between
|
|
9
|
+
* chunks. Most importantly, this lets the Kubernetes liveness and
|
|
10
|
+
* readiness probe handlers (/status/live, /status/ready) run. Without a
|
|
11
|
+
* periodic yield a large batch pins the single-threaded event loop for
|
|
12
|
+
* seconds at a time, the probe HTTP handler never gets scheduled, the
|
|
13
|
+
* kubelet marks the probe as failed, and the pod is restarted.
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT: this is implemented with setImmediate, NOT
|
|
16
|
+
* `await Promise.resolve()`. Awaiting a resolved promise only drains the
|
|
17
|
+
* microtask queue; the event loop never advances to its poll phase, so
|
|
18
|
+
* queued I/O (including probe requests) stays starved no matter how often
|
|
19
|
+
* you await. setImmediate schedules a macrotask in the check phase, which
|
|
20
|
+
* runs only after the poll phase has had a chance to process I/O — so a
|
|
21
|
+
* loop that periodically awaits this genuinely unblocks the event loop.
|
|
22
|
+
*/
|
|
23
|
+
public static async yieldToEventLoop(): Promise<void> {
|
|
24
|
+
return new Promise<void>((resolve: () => void) => {
|
|
25
|
+
setImmediate(resolve);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default class EventLoop {
|
|
2
|
+
/**
|
|
3
|
+
* Yields control back to the Node.js event loop, resuming on a later
|
|
4
|
+
* "check" phase tick.
|
|
5
|
+
*
|
|
6
|
+
* Use this to break up CPU-bound synchronous work — e.g. transforming
|
|
7
|
+
* tens of thousands of OTLP datapoints / spans / log records inside a
|
|
8
|
+
* single ingest job — so the process can service pending I/O between
|
|
9
|
+
* chunks. Most importantly, this lets the Kubernetes liveness and
|
|
10
|
+
* readiness probe handlers (/status/live, /status/ready) run. Without a
|
|
11
|
+
* periodic yield a large batch pins the single-threaded event loop for
|
|
12
|
+
* seconds at a time, the probe HTTP handler never gets scheduled, the
|
|
13
|
+
* kubelet marks the probe as failed, and the pod is restarted.
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT: this is implemented with setImmediate, NOT
|
|
16
|
+
* `await Promise.resolve()`. Awaiting a resolved promise only drains the
|
|
17
|
+
* microtask queue; the event loop never advances to its poll phase, so
|
|
18
|
+
* queued I/O (including probe requests) stays starved no matter how often
|
|
19
|
+
* you await. setImmediate schedules a macrotask in the check phase, which
|
|
20
|
+
* runs only after the poll phase has had a chance to process I/O — so a
|
|
21
|
+
* loop that periodically awaits this genuinely unblocks the event loop.
|
|
22
|
+
*/
|
|
23
|
+
static async yieldToEventLoop() {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
setImmediate(resolve);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=EventLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventLoop.js","sourceRoot":"","sources":["../../../../Server/Utils/EventLoop.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,MAAM,CAAC,KAAK,CAAC,gBAAgB;QAClC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAmB,EAAE,EAAE;YAC/C,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|