Skip to content

Commit ecc4729

Browse files
authored
Fix max_runner_memory_usage_bytes flag default logic (#4965)
1 parent afd5816 commit ecc4729

File tree

1 file changed

+13
-6
lines changed
  • enterprise/server/remote_execution/runner

1 file changed

+13
-6
lines changed

enterprise/server/remote_execution/runner/runner.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
maxRunnerDiskSizeBytes = flag.Int64("executor.runner_pool.max_runner_disk_size_bytes", 16e9, "Maximum disk size for a recycled runner; runners exceeding this threshold are not recycled. Defaults to 16GB.")
6565
// How much memory a runner is allowed to use before we decide that it
6666
// can't be added to the pool and must be cleaned up instead.
67-
maxRunnerMemoryUsageBytes = flag.Int64("executor.runner_pool.max_runner_memory_usage_bytes", tasksize.WorkflowMemEstimate, "Maximum memory usage for a recycled runner; runners exceeding this threshold are not recycled. Defaults to 1/10 of total RAM allocated to the executor. (Only supported for Docker-based executors).")
67+
maxRunnerMemoryUsageBytes = flag.Int64("executor.runner_pool.max_runner_memory_usage_bytes", 0, "Maximum memory usage for a recycled runner; runners exceeding this threshold are not recycled.")
6868
podmanWarmupDefaultImages = flag.Bool("executor.podman.warmup_default_images", true, "Whether to warmup the default podman images or not.")
6969
)
7070

@@ -91,6 +91,9 @@ const (
9191
// after we send the shutdown signal before giving up.
9292
persistentWorkerShutdownTimeout = 10 * time.Second
9393

94+
// Default value of maxRunnerMemoryUsageBytes.
95+
defaultMaxRunnerMemoryUsageBytes = 2e9 // 2GiB
96+
9497
// Memory usage estimate multiplier for pooled runners, relative to the
9598
// default memory estimate for execution tasks.
9699
runnerMemUsageEstimateMultiplierBytes = 6.5
@@ -610,11 +613,11 @@ func (p *pool) add(ctx context.Context, r *commandRunner) *labeledError {
610613
"stats_failed",
611614
}
612615
}
613-
// If memory usage stats are not implemented, fall back to the default task
614-
// size estimate.
616+
// If memory usage stats are not implemented, use the configured per-runner
617+
// limit as a (very) rough estimate.
615618
if stats == nil {
616619
stats = &repb.UsageStats{}
617-
stats.MemoryBytes = int64(float64(tasksize.DefaultMemEstimate) * runnerMemUsageEstimateMultiplierBytes)
620+
stats.MemoryBytes = p.maxRunnerMemoryUsageBytes
618621
}
619622

620623
if stats.MemoryBytes > p.maxRunnerMemoryUsageBytes {
@@ -1353,12 +1356,16 @@ func (p *pool) setLimits() {
13531356
}
13541357

13551358
mem := *maxRunnerMemoryUsageBytes
1356-
if mem > totalRAMBytes {
1357-
mem = totalRAMBytes
1359+
if mem == 0 {
1360+
mem = defaultMaxRunnerMemoryUsageBytes
13581361
} else if mem < 0 {
13591362
// < 0 means no limit.
13601363
mem = math.MaxInt64
13611364
}
1365+
// Per-runner limit shouldn't exceed total allocated RAM.
1366+
if mem > totalRAMBytes {
1367+
mem = totalRAMBytes
1368+
}
13621369

13631370
disk := *maxRunnerDiskSizeBytes
13641371
if disk < 0 {

0 commit comments

Comments
 (0)