From 7e2acccd1ebd80750a3ebdb96cb5c36b5263cc24 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Sun, 17 Mar 2024 18:41:26 +0000 Subject: [PATCH] feat(worker): allow number of threads to be configured This allows for more threads to be run. Care needs to be taken to ensure that database connection pool size is appropriate for this. --- app/lib/worker/process.rb | 4 +++- doc/config/environment-variables.md | 1 + doc/config/yaml.yml | 2 ++ lib/postal/config_schema.rb | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/lib/worker/process.rb b/app/lib/worker/process.rb index 277545b..1445800 100644 --- a/app/lib/worker/process.rb +++ b/app/lib/worker/process.rb @@ -45,7 +45,9 @@ module Worker ].freeze # @param [Integer] thread_count The number of worker threads to run in this process - def initialize(thread_count: 2, work_sleep_time: 5, task_sleep_time: 60) + def initialize(thread_count: Postal::Config.worker.threads, + work_sleep_time: 5, + task_sleep_time: 60) @thread_count = thread_count @exit_pipe_read, @exit_pipe_write = IO.pipe @work_sleep_time = work_sleep_time diff --git a/doc/config/environment-variables.md b/doc/config/environment-variables.md index 513d6db..1b6e0dd 100644 --- a/doc/config/environment-variables.md +++ b/doc/config/environment-variables.md @@ -25,6 +25,7 @@ This document contains all the environment variables which are available for thi | `WEB_SERVER_MAX_THREADS` | Integer | The maximum number of threads which can be used by the web server | 5 | | `WORKER_DEFAULT_HEALTH_SERVER_PORT` | Integer | The default port for the worker health server to listen on | 9090 | | `WORKER_DEFAULT_HEALTH_SERVER_BIND_ADDRESS` | String | The default bind address for the worker health server to listen on | 127.0.0.1 | +| `WORKER_THREADS` | Integer | The number of threads to execute within each worker | 2 | | `MAIN_DB_HOST` | String | Hostname for the main MariaDB server | localhost | | `MAIN_DB_PORT` | Integer | The MariaDB port to connect to | 3306 | | `MAIN_DB_USERNAME` | String | The MariaDB username | postal | diff --git a/doc/config/yaml.yml b/doc/config/yaml.yml index 4f45c75..1035ec9 100644 --- a/doc/config/yaml.yml +++ b/doc/config/yaml.yml @@ -47,6 +47,8 @@ worker: default_health_server_port: 9090 # The default bind address for the worker health server to listen on default_health_server_bind_address: 127.0.0.1 + # The number of threads to execute within each worker + threads: 2 main_db: # Hostname for the main MariaDB server diff --git a/lib/postal/config_schema.rb b/lib/postal/config_schema.rb index 6000bfc..af3c733 100644 --- a/lib/postal/config_schema.rb +++ b/lib/postal/config_schema.rb @@ -130,6 +130,11 @@ module Postal description "The default bind address for the worker health server to listen on" default "127.0.0.1" end + + integer :threads do + description "The number of threads to execute within each worker" + default 2 + end end group :main_db do