Skip to content

Commit

Permalink
feat(worker): allow number of threads to be configured
Browse files Browse the repository at this point in the history
This allows for more threads to be run. Care needs to be taken to ensure that database connection pool size is appropriate for this.
  • Loading branch information
adamcooke committed Mar 17, 2024
1 parent ee8d829 commit 7e2accc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/lib/worker/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class Process
].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
Expand Down
1 change: 1 addition & 0 deletions doc/config/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions doc/config/yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/postal/config_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e2accc

Please sign in to comment.