Skip to content

Commit 8a59d60

Browse files
committed
builder_worker: make number of workers configureable
1 parent 474d5e4 commit 8a59d60

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

buildbot_nix/buildbot_nix/worker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ class WorkerConfig:
2525
worker_name: str = field(
2626
default_factory=lambda: os.environ.get("WORKER_NAME", socket.gethostname())
2727
)
28-
worker_count: int = int(
29-
os.environ.get("WORKER_COUNT", str(multiprocessing.cpu_count())),
30-
)
28+
worker_count_str: str | None = os.environ.get("WORKER_COUNT")
29+
if worker_count_str is not None:
30+
worker_count = int(worker_count_str)
31+
else:
32+
worker_count = multiprocessing.cpu_count()
3133
buildbot_dir: Path = field(
3234
default_factory=lambda: Path(require_env("BUILDBOT_DIR"))
3335
)

examples/worker.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
services.buildbot-nix.worker = {
44
enable = true;
55
workerPasswordFile = pkgs.writeText "worker-password-file" "XXXXXXXXXXXXXXXXXXXX";
6+
# The number of workers to start (default: 0 == the number of CPU cores).
7+
# If you experience flaky builds under high load, try to reduce this value.
8+
# workers = 0;
69
};
710
}

nix/worker.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ in
5656
default = pkgs.nix-eval-jobs;
5757
description = "nix-eval-jobs to use for evaluation";
5858
};
59+
workers = lib.mkOption {
60+
type = lib.types.int;
61+
default = 0;
62+
description = ''
63+
The number of workers to start (default: 0 == to the number of CPU cores).
64+
If you experience flaky builds under high load, try to reduce this value.
65+
'';
66+
};
5967
masterUrl = lib.mkOption {
6068
type = lib.types.str;
6169
default = "tcp:host=localhost:port=9989";
@@ -114,6 +122,7 @@ in
114122
}/${packages.python.sitePackages}";
115123
environment.MASTER_URL = cfg.masterUrl;
116124
environment.BUILDBOT_DIR = buildbotDir;
125+
environment.WORKER_COUNT = builtins.toString cfg.workers;
117126

118127
serviceConfig = {
119128
# We rather want the CI job to fail on OOM than to have a broken buildbot worker.

0 commit comments

Comments
 (0)