From ec3cf7590617f6adbd2901c0e5e4ec9ec9cca924 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 28 Aug 2025 19:49:29 +0100 Subject: [PATCH] spindle: allowing configuring queue size and max job count Change-Id: vtunvupqotuoutqpmwlkqrnptsktmkxm Signed-off-by: oppiliappan --- nix/modules/spindle.nix | 16 ++++++++++++++++ nix/vm.nix | 2 ++ spindle/config/config.go | 2 ++ spindle/server.go | 3 ++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/nix/modules/spindle.nix b/nix/modules/spindle.nix index 35e6a6bc..e3f37f48 100644 --- a/nix/modules/spindle.nix +++ b/nix/modules/spindle.nix @@ -55,6 +55,20 @@ in description = "DID of owner (required)"; }; + maxJobCount = mkOption { + type = types.int; + default = 2; + example = 5; + description = "Maximum number of concurrent jobs to run"; + }; + + queueSize = mkOption { + type = types.int; + default = 100; + example = 100; + description = "Maximum number of jobs queue up"; + }; + secrets = { provider = mkOption { type = types.str; @@ -108,6 +122,8 @@ in "SPINDLE_SERVER_JETSTREAM=${cfg.server.jetstreamEndpoint}" "SPINDLE_SERVER_DEV=${lib.boolToString cfg.server.dev}" "SPINDLE_SERVER_OWNER=${cfg.server.owner}" + "SPINDLE_SERVER_MAX_JOB_COUNT=${toString cfg.server.maxJobCount}" + "SPINDLE_SERVER_QUEUE_SIZE=${toString cfg.server.queueSize}" "SPINDLE_SERVER_SECRETS_PROVIDER=${cfg.server.secrets.provider}" "SPINDLE_SERVER_SECRETS_OPENBAO_PROXY_ADDR=${cfg.server.secrets.openbao.proxyAddr}" "SPINDLE_SERVER_SECRETS_OPENBAO_MOUNT=${cfg.server.secrets.openbao.mount}" diff --git a/nix/vm.nix b/nix/vm.nix index a54e282f..33a2a5d5 100644 --- a/nix/vm.nix +++ b/nix/vm.nix @@ -89,6 +89,8 @@ in hostname = "localhost:6555"; listenAddr = "0.0.0.0:6555"; dev = true; + queueSize = 100; + maxJobCount = 2; secrets = { provider = "sqlite"; }; diff --git a/spindle/config/config.go b/spindle/config/config.go index 5719c5c4..1fa6846a 100644 --- a/spindle/config/config.go +++ b/spindle/config/config.go @@ -17,6 +17,8 @@ type Server struct { Owner string `env:"OWNER, required"` Secrets Secrets `env:",prefix=SECRETS_"` LogDir string `env:"LOG_DIR, default=/var/log/spindle"` + QueueSize int `env:"QUEUE_SIZE, default=100"` + MaxJobCount int `env:"MAX_JOB_COUNT, default=2"` // max number of jobs that run at a time } func (s Server) Did() syntax.DID { diff --git a/spindle/server.go b/spindle/server.go index 75563f4c..ca34f169 100644 --- a/spindle/server.go +++ b/spindle/server.go @@ -100,7 +100,8 @@ func Run(ctx context.Context) error { return err } - jq := queue.NewQueue(100, 5) + jq := queue.NewQueue(cfg.Server.QueueSize, cfg.Server.MaxJobCount) + logger.Info("initialized queue", "queueSize", cfg.Server.QueueSize, "numWorkers", cfg.Server.MaxJobCount) collections := []string{ tangled.SpindleMemberNSID, -- 2.43.0