Skip to content

Commit f05fe25

Browse files
committed
perf(supervisor): inspect Docker resources concurrently (#3727)
1 parent 14824b0 commit f05fe25

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: supervisor
3+
type: improvement
4+
---
5+
6+
Resource availability checks now update faster when many task containers are running.

apps/supervisor/src/resourceMonitor.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,21 @@ export class DockerResourceMonitor extends ResourceMonitor {
132132
let cpuUsed = 0;
133133
let memoryUsed = 0;
134134

135-
for (const container of stats) {
136-
if (container.State === "running") {
137-
const c = this.docker.getContainer(container.Id);
138-
const { HostConfig } = await c.inspect();
139-
140-
const cpu = this.resourceParser.cpu(HostConfig.NanoCpus ?? 0);
141-
const memory = this.resourceParser.memory(HostConfig.Memory ?? 0);
142-
143-
cpuUsed += cpu;
144-
memoryUsed += memory;
145-
}
135+
const runningContainers = stats.filter((container) => container.State === "running");
136+
const inspectedResources = await Promise.all(
137+
runningContainers.map(async (container) => {
138+
const { HostConfig } = await this.docker.getContainer(container.Id).inspect();
139+
140+
return {
141+
cpu: this.resourceParser.cpu(HostConfig.NanoCpus ?? 0),
142+
memory: this.resourceParser.memory(HostConfig.Memory ?? 0),
143+
};
144+
})
145+
);
146+
147+
for (const resources of inspectedResources) {
148+
cpuUsed += resources.cpu;
149+
memoryUsed += resources.memory;
146150
}
147151

148152
this.cachedResources = this.applyOverrides({

0 commit comments

Comments
 (0)