Skip to content

Commit 78cfc92

Browse files
committed
Allow sampling runner disk usage to reduce CPU (#8909)
Context: buildbuddy-io/buildbuddy-internal#4789 If we sample runner disk usage with, say, 10% probability instead of 100%, then this should free up somewhere between 250m and 1000m CPU capacity on each of the macs mentioned in the linked issue when the executor is under high load.
1 parent 058966a commit 78cfc92

File tree

1 file changed

+20
-12
lines changed
  • enterprise/server/remote_execution/runner

1 file changed

+20
-12
lines changed

enterprise/server/remote_execution/runner/runner.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"syscall"
1313
"time"
1414

15+
mrand "math/rand/v2"
16+
1517
"github.com/buildbuddy-io/buildbuddy/enterprise/server/auth"
1618
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/block_io"
1719
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/commandutil"
@@ -57,7 +59,8 @@ var (
5759
maxRunnerCount = flag.Int("executor.runner_pool.max_runner_count", 0, "Maximum number of recycled RBE runners that can be pooled at once. Defaults to a value derived from estimated CPU usage, max RAM, allocated CPU, and allocated memory.")
5860
// How big a runner's workspace is allowed to get before we decide that it
5961
// can't be added to the pool and must be cleaned up instead.
60-
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.")
62+
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.")
63+
runnerDiskUsageSampleRate = flag.Float64("executor.runner_pool.runner_disk_usage_sample_rate", 1.0, "Sample rate of runner disk usage. Setting this to a lower value can reduce CPU usage due to runner disk space checking, but may increase the risk of running out of disk space.")
6164
// How much memory a runner is allowed to use before we decide that it
6265
// can't be added to the pool and must be cleaned up instead.
6366
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.")
@@ -678,18 +681,23 @@ func (p *pool) add(ctx context.Context, r *taskRunner) *labeledError {
678681
"max_memory_exceeded",
679682
}
680683
}
681-
du, err := r.Workspace.DiskUsageBytes()
682-
if err != nil {
683-
return &labeledError{
684-
status.WrapError(err, "failed to compute runner disk usage"),
685-
"compute_disk_usage_failed",
684+
685+
var diskUsageBytes int64
686+
if *runnerDiskUsageSampleRate >= 1.0 || mrand.Float64() < *runnerDiskUsageSampleRate {
687+
du, err := r.Workspace.DiskUsageBytes()
688+
if err != nil {
689+
return &labeledError{
690+
status.WrapError(err, "failed to compute runner disk usage"),
691+
"compute_disk_usage_failed",
692+
}
686693
}
687-
}
688-
if du > p.maxRunnerDiskUsageBytes {
689-
return &labeledError{
690-
status.ResourceExhaustedErrorf("runner disk usage of %d bytes exceeds limit of %d bytes", du, p.maxRunnerDiskUsageBytes),
691-
"max_disk_usage_exceeded",
694+
if du > p.maxRunnerDiskUsageBytes {
695+
return &labeledError{
696+
status.ResourceExhaustedErrorf("runner disk usage of %d bytes exceeds limit of %d bytes", du, p.maxRunnerDiskUsageBytes),
697+
"max_disk_usage_exceeded",
698+
}
692699
}
700+
diskUsageBytes = du
693701
}
694702

695703
p.mu.Lock()
@@ -749,7 +757,7 @@ func (p *pool) add(ctx context.Context, r *taskRunner) *labeledError {
749757
// Cache resource usage values so we don't need to recompute them when
750758
// updating metrics upon removal.
751759
r.memoryUsageBytes = stats.MemoryBytes
752-
r.diskUsageBytes = du
760+
r.diskUsageBytes = diskUsageBytes
753761

754762
metrics.RunnerPoolDiskUsageBytes.Add(float64(r.diskUsageBytes))
755763
metrics.RunnerPoolMemoryUsageBytes.Add(float64(r.memoryUsageBytes))

0 commit comments

Comments
 (0)