Scale akkounts Solid Queue workers and guard unit memory

Size the akkounts background workers for the 4 GB / 4 vCPU VM:

* JOB_CONCURRENCY=6 scales the `default,nostr` worker group.
* NOSTR_CONNECT_THREADS=24 and NOSTR_RPC_THREADS=4 size the separate
  nostr_connect (long-blocking listeners) and nostr_rpc (signing) pools.
* DB_POOL=24 keeps the pool >= the largest worker thread count.

Also cap the unit with MemoryHigh/MemoryMax, and restart the service when
the unit body changes since it now carries this configuration.
This commit is contained in:
raucao committed 2026-11-27 17:09:30 +04:00
1 parent 3a3d23ea09
commit 05d58872fe
1 file changed
+20 -1
@@ -249,12 +249,27 @@ systemd_unit "akkounts.service" do
Type: "simple",
User: deploy_user,
WorkingDirectory: deploy_path,
Environment: "RAILS_ENV=#{rails_env} SOLID_QUEUE_IN_PUMA=true",
# Solid Queue worker sizing (see config/queue.yml in the app):
# * JOB_CONCURRENCY scales the `default,nostr` group's processes; each
# extra process costs ~60-90 MB.
# * NOSTR_CONNECT_THREADS sizes the `nostr_connect` listener pool. Those
# jobs block a thread for up to 5 min on relay websockets, so they get
# many cheap threads instead of processes.
# * NOSTR_RPC_THREADS sizes the separate signing pool so sign events
# never queue behind the long-running listeners.
# * DB_POOL must be >= the largest thread count, or worker threads hit
# ActiveRecord::ConnectionTimeoutError under load.
Environment: "RAILS_ENV=#{rails_env} SOLID_QUEUE_IN_PUMA=true " \
"JOB_CONCURRENCY=6 NOSTR_CONNECT_THREADS=24 " \
"NOSTR_RPC_THREADS=4 DB_POOL=24",
ExecStart: "#{bundle_path} exec puma -C config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid",
ExecReload: "#{bundle_path} exec pumactl -F config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid phased-restart",
PIDFile: "#{deploy_path}/tmp/puma.pid",
TimeoutSec: "30",
Restart: "always",
# Guard against a runaway worker triggering the host-wide OOM killer.
MemoryHigh: "3G",
MemoryMax: "3500M",
},
Install: {
WantedBy: "multi-user.target"
@@ -263,6 +278,10 @@ systemd_unit "akkounts.service" do
verify false
triggers_reload true
action [:create, :enable]
# The unit body carries JOB_CONCURRENCY (and the memory guards), so a change
# here must restart the service to take effect. Nothing else notifies it
# unless the git checkout / .env also change.
notifies :restart, "service[#{app_name}]", :delayed
end
deploy_env = {