From 38bc1b413d1762280aaf6305c24bd5d3be5c1bec Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 23 Jan 2025 15:59:24 +0100 Subject: [PATCH] cli: Make the CLI cgroups-aware Honoring cgroups limits on CPUs is useful when running `bb explain` in a workflow, such as in the "Compare" Bazel button. --- MODULE.bazel | 1 + cli/cmd/bb/BUILD | 1 + cli/cmd/bb/bb.go | 3 +++ deps.bzl | 12 ++++++++++++ go.mod | 1 + go.sum | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index 74864c3d693..97500616d67 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -394,6 +394,7 @@ use_repo( "org_golang_x_time", "org_golang_x_tools", "org_uber_go_atomic", + "org_uber_go_automaxprocs", ) # Note that this is 'rules_nodejs-core' diff --git a/cli/cmd/bb/BUILD b/cli/cmd/bb/BUILD index 8e90f77b9c2..fb017769050 100644 --- a/cli/cmd/bb/BUILD +++ b/cli/cmd/bb/BUILD @@ -25,6 +25,7 @@ go_library( "//cli/watcher", "//server/util/rlimit", "//server/util/status", + "@org_uber_go_automaxprocs//:automaxprocs", ], ) diff --git a/cli/cmd/bb/bb.go b/cli/cmd/bb/bb.go index 307b49ee343..b4729f4e2d0 100644 --- a/cli/cmd/bb/bb.go +++ b/cli/cmd/bb/bb.go @@ -22,6 +22,9 @@ import ( "github.com/buildbuddy-io/buildbuddy/server/util/status" sidecarmain "github.com/buildbuddy-io/buildbuddy/cli/cmd/sidecar" + + // Make GOMAXPROCS cgroups-aware. + _ "go.uber.org/automaxprocs" ) var ( diff --git a/deps.bzl b/deps.bzl index 4cd2da336ff..ad39e12b671 100644 --- a/deps.bzl +++ b/deps.bzl @@ -3954,6 +3954,12 @@ def install_go_mod_dependencies(workspace_name = "buildbuddy"): sum = "h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20=", version = "v0.0.0-20190930134022-aa0246cd15f7", ) + go_repository( + name = "com_github_prashantv_gostub", + importpath = "github.com/prashantv/gostub", + sum = "h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=", + version = "v1.1.0", + ) go_repository( name = "com_github_prometheus_client_golang", build_directives = [ @@ -6353,6 +6359,12 @@ def install_go_mod_dependencies(workspace_name = "buildbuddy"): sum = "h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=", version = "v1.11.0", ) + go_repository( + name = "org_uber_go_automaxprocs", + importpath = "go.uber.org/automaxprocs", + sum = "h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=", + version = "v1.6.0", + ) go_repository( name = "org_uber_go_goleak", importpath = "go.uber.org/goleak", diff --git a/go.mod b/go.mod index d5e8c60aecc..4c3d32fefdb 100644 --- a/go.mod +++ b/go.mod @@ -136,6 +136,7 @@ require ( go.opentelemetry.io/otel/sdk v1.29.0 go.opentelemetry.io/otel/trace v1.31.0 go.uber.org/atomic v1.11.0 + go.uber.org/automaxprocs v1.6.0 golang.org/x/crypto v0.31.0 golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/mod v0.20.0 diff --git a/go.sum b/go.sum index 6d0fb269a93..a65be883e31 100644 --- a/go.sum +++ b/go.sum @@ -1401,6 +1401,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:Om github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig= github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -1738,6 +1740,8 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= +go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=