Skip to content

Commit 1083f31

Browse files
committed
api/v2/exec: get rid of ttl purge and ylim = 0 in the plot
1 parent bd3db0c commit 1083f31

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/packages/backend/execute-code.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,32 @@ const MONITOR_STATS_LENGTH_MAX = envToInt(
4949
100,
5050
);
5151

52+
log.debug("configuration:", {
53+
ASYNC_CACHE_MAX,
54+
ASYNC_CACHE_TTL_S,
55+
MONITOR_INTERVAL_S,
56+
MONITOR_STATS_LENGTH_MAX,
57+
});
58+
5259
const asyncCache = new LRU<string, ExecuteCodeOutputAsync>({
5360
max: ASYNC_CACHE_MAX,
5461
ttl: 1000 * ASYNC_CACHE_TTL_S,
55-
ttlAutopurge: true,
56-
allowStale: true,
5762
updateAgeOnGet: true,
5863
updateAgeOnHas: true,
5964
});
6065

66+
function truncStats(obj?: ExecuteCodeOutputAsync) {
67+
if (Array.isArray(obj?.stats)) {
68+
// truncate to $MONITOR_STATS_LENGTH_MAX, by discarding the inital entries
69+
obj.stats = obj.stats.slice(obj.stats.length - MONITOR_STATS_LENGTH_MAX);
70+
}
71+
}
72+
6173
function asyncCacheUpdate(job_id: string, upd) {
6274
const obj = asyncCache.get(job_id);
6375
if (Array.isArray(obj?.stats) && Array.isArray(upd.stats)) {
6476
obj.stats.push(...upd.stats);
65-
// truncate to $MONITOR_STATS_LENGTH_MAX, by discarding the inital entries
66-
obj.stats = obj.stats.slice(obj.stats.length - MONITOR_STATS_LENGTH_MAX);
77+
truncStats(obj);
6778
}
6879
asyncCache.set(job_id, { ...obj, ...upd });
6980
}
@@ -324,7 +335,7 @@ function doSpawn(
324335
let stderr_is_done = false;
325336
let stdout_is_done = false;
326337
let killed = false;
327-
let callback_done = false;
338+
let callback_done = false; // set in "finish", which is also called in a timeout
328339
let timer: NodeJS.Timeout | undefined = undefined;
329340

330341
// periodically check up on the child process tree and record stats
@@ -360,6 +371,7 @@ function doSpawn(
360371
cpu_pct: pct_cpu,
361372
cpu_secs,
362373
});
374+
truncStats(obj);
363375
asyncCache.set(job_id, obj);
364376

365377
// initially, we record more frequently, but then we space it out up until the interval (probably 1 minute)

src/packages/next/lib/api/schema/exec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ ax1.plot(timestamps, mem_rss, color='blue', label='Memory (RSS)')
214214
ax1.set_xlabel('Time')
215215
ax1.set_ylabel('Memory (MB)', color='blue')
216216
ax1.tick_params(axis='y', labelcolor='blue')
217+
ax1.set_ylim(bottom=0)
217218
218219
# CPU utilization (secondary axis)
219220
ax2 = ax1.twinx()
220221
ax2.plot(timestamps, cpu_pct, color='red', label='CPU (%)')
221222
ax2.set_ylabel('CPU (%)', color='red')
222223
ax2.tick_params(axis='y', labelcolor='red')
224+
ax2.set_ylim(bottom=0)
223225
224226
# Add labels and legend
225227
plt.title('Job Stats')

0 commit comments

Comments
 (0)