Skip to content

Commit 9d40215

Browse files
committed
warn on exceeding thresholds
1 parent 44fe332 commit 9d40215

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/core/src/shared/utilities/processUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export const eof = Symbol('EOF')
6666

6767
class ChildProcessTracker extends Map<number, ChildProcess> {
6868
static pollingInterval: number = 1000
69+
static thresholds: { memory: number; cpu: number; time: number } = {
70+
memory: 100 * 1024 * 1024, // 100 MB
71+
cpu: 50,
72+
time: 30 * 1000, // 30 seconds
73+
}
74+
6975
#processPoller: PollingSet<number>
7076

7177
public constructor() {
@@ -96,6 +102,15 @@ class ChildProcessTracker extends Map<number, ChildProcess> {
96102
if (this.has(pid)) {
97103
const stats = await pidusage(pid)
98104
getLogger().debug(`stats for ${pid}: %O`, stats)
105+
if (stats.memory > ChildProcessTracker.thresholds.memory) {
106+
getLogger().warn(`Process ${pid} exceeded memory threshold: ${stats.memory}`)
107+
}
108+
if (stats.cpu > ChildProcessTracker.thresholds.cpu) {
109+
getLogger().warn(`Process ${pid} exceeded cpu threshold: ${stats.cpu}`)
110+
}
111+
if (stats.elapsed > ChildProcessTracker.thresholds.time) {
112+
getLogger().warn(`Process ${pid} exceeded time threshold: ${stats.elapsed}`)
113+
}
99114
} else {
100115
getLogger().warn(`Missing process with id ${pid}`)
101116
}

0 commit comments

Comments
 (0)