Skip to content

Commit aae93f8

Browse files
authored
fix(execution): cap isolate memory at 128MB and recycle workers every 200 executions (#4543)
* fix(execution): cap isolate memory at 128MB and recycle workers every 100 executions * fix(execution): set IVM_MAX_EXECUTIONS_PER_WORKER env default to 100 * fix(execution): raise MAX_EXECUTIONS_PER_WORKER from 100 to 200 * fix(execution): update memory limit error messages from 256 MB to 128 MB
1 parent 94f60e7 commit aae93f8

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

apps/sim/lib/core/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const env = createEnv({
248248
IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER:z.string().optional().default('2200'), // Max owner in-flight leases across replicas
249249
IVM_DISTRIBUTED_LEASE_MIN_TTL_MS: z.string().optional().default('120000'), // Min TTL for distributed in-flight leases (ms)
250250
IVM_QUEUE_TIMEOUT_MS: z.string().optional().default('300000'), // Max queue wait before rejection (ms)
251-
IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('500'), // Max lifetime executions before worker is recycled
251+
IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('200'), // Max lifetime executions before worker is recycled
252252
IVM_MAX_BROKER_ARGS_JSON_CHARS: z.string().optional().default('262144'), // Max JSON payload size for sandbox task broker args (isolate→host)
253253
IVM_MAX_BROKER_RESULT_JSON_CHARS: z.string().optional().default('16777216'),// Max JSON payload size for sandbox task broker results (host→isolate)
254254
IVM_MAX_BROKERS_PER_EXECUTION: z.string().optional().default('1000'), // Max broker calls per sandbox task execution

apps/sim/lib/execution/isolated-vm-worker.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async function executeCode(request, executionId) {
183183
const externalCopies = []
184184

185185
try {
186-
isolate = new ivm.Isolate({ memoryLimit: 256 })
186+
isolate = new ivm.Isolate({ memoryLimit: 128 })
187187
if (executionId !== undefined) activeIsolates.set(executionId, isolate)
188188
context = await isolate.createContext()
189189
const jail = context.global
@@ -388,7 +388,7 @@ async function executeCode(request, executionId) {
388388
stdout,
389389
error: {
390390
message:
391-
'Execution exceeded memory limit (256 MB). Reduce image sizes or split the work into smaller batches.',
391+
'Execution exceeded memory limit (128 MB). Reduce image sizes or split the work into smaller batches.',
392392
name: 'MemoryLimitError',
393393
},
394394
}
@@ -529,7 +529,7 @@ async function executeTask(request, executionId) {
529529
let tPhase = tStart
530530

531531
try {
532-
isolate = new ivm.Isolate({ memoryLimit: 256 })
532+
isolate = new ivm.Isolate({ memoryLimit: 128 })
533533
if (executionId !== undefined) activeIsolates.set(executionId, isolate)
534534
context = await isolate.createContext()
535535
const jail = context.global
@@ -945,7 +945,7 @@ async function executeTask(request, executionId) {
945945
stdout,
946946
error: {
947947
message:
948-
'Execution exceeded memory limit (256 MB). Reduce image sizes or split the work into smaller batches.',
948+
'Execution exceeded memory limit (128 MB). Reduce image sizes or split the work into smaller batches.',
949949
name: 'MemoryLimitError',
950950
},
951951
timings,

apps/sim/lib/execution/isolated-vm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const DISTRIBUTED_MAX_INFLIGHT_PER_OWNER =
128128
Number.parseInt(env.IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER) ||
129129
MAX_ACTIVE_PER_OWNER + MAX_QUEUED_PER_OWNER
130130
const DISTRIBUTED_LEASE_MIN_TTL_MS = Number.parseInt(env.IVM_DISTRIBUTED_LEASE_MIN_TTL_MS) || 120000
131-
const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 500
131+
const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 200
132132
const MAX_BROKER_ARGS_JSON_CHARS = Number.parseInt(env.IVM_MAX_BROKER_ARGS_JSON_CHARS) || 262_144
133133
const MAX_BROKER_RESULT_JSON_CHARS =
134134
Number.parseInt(env.IVM_MAX_BROKER_RESULT_JSON_CHARS) || 16_777_216

0 commit comments

Comments
 (0)