Skip to content

Commit 747a8d0

Browse files
committed
Allow us to configure web concurrency
Part of RaspberryPiFoundation/digital-editor-issues#1133 We're currently running with a single process (puma web worker) which may mean a single long running request can block our server and cause other requests to fail. Now we have upgraded to a performance dyno, we have enough RAM to run web workers (Heroku recommends using 2). I've make this configurable (starting with 1) so that it's easier to change (which we would need to do if we are RAM constrained).
1 parent eec9168 commit 747a8d0

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

config/puma.rb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@
2626
# Specifies the `pidfile` that Puma will use.
2727
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
2828

29-
# Specifies the number of `workers` to boot in clustered mode.
30-
# Workers are forked web server processes. If using threads and workers together
31-
# the concurrency of the application would be max `threads` * `workers`.
32-
# Workers do not work on JRuby or Windows (both of which do not support
33-
# processes).
34-
#
35-
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
29+
worker_count = ENV.fetch('WEB_CONCURRENCY', 1).to_i
3630

37-
# Use the `preload_app!` method when specifying a `workers` number.
38-
# This directive tells Puma to first boot the application and load code
39-
# before forking the application. This takes advantage of Copy On Write
40-
# process behavior so workers use less memory.
41-
#
42-
# preload_app!
31+
if worker_count > 1
32+
33+
# Specifies the number of `workers` to boot in clustered mode.
34+
# Workers are forked web server processes. If using threads and workers together
35+
# the concurrency of the application would be max `threads` * `workers`.
36+
# Workers do not work on JRuby or Windows (both of which do not support
37+
# processes).
38+
39+
workers worker_count
40+
41+
# Use the `preload_app!` method when specifying a `workers` number.
42+
# This directive tells Puma to first boot the application and load code
43+
# before forking the application. This takes advantage of Copy On Write
44+
# process behavior so workers use less memory.
45+
46+
preload_app!
47+
end
4348

4449
# Allow puma to be restarted by `bin/rails restart` command.
4550
plugin :tmp_restart

0 commit comments

Comments
 (0)