From eec9168b87cb2152b1284fd99b422fdf52396d09 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Mon, 16 Feb 2026 09:02:29 +0000 Subject: [PATCH 1/2] Upgrade to latest Puma version I've checked the changelog and can't see any changes that affect us --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 1844efe5..3cee01d6 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ gem 'open-uri' gem 'paper_trail' gem 'pg', '~> 1.1' gem 'postmark-rails' -gem 'puma', '~> 6' +gem 'puma', '~> 7.2' gem 'rack-cors' gem 'rails', '~> 7.1' gem 'sentry-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 61a798b0..f4985433 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -352,7 +352,7 @@ GEM date stringio public_suffix (6.0.2) - puma (6.6.1) + puma (7.2.0) nio4r (~> 2.0) raabro (1.4.0) racc (1.8.1) @@ -616,7 +616,7 @@ DEPENDENCIES pg (~> 1.1) postmark-rails pry-byebug - puma (~> 6) + puma (~> 7.2) rack-cors rails (~> 7.1) rails-erd From 747a8d06241543bcec42bc8d74d0014f7b8c0166 Mon Sep 17 00:00:00 2001 From: Chris Zetter <253059100+zetter-rpf@users.noreply.github.com> Date: Mon, 16 Feb 2026 09:22:18 +0000 Subject: [PATCH 2/2] Allow us to configure web concurrency Part of https://github.com/RaspberryPiFoundation/digital-editor-issues/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). --- config/puma.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 1713441e..71f0f48f 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -26,20 +26,25 @@ # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked web server processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } +worker_count = ENV.fetch('WEB_CONCURRENCY', 1).to_i -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. -# -# preload_app! +if worker_count > 1 + + # Specifies the number of `workers` to boot in clustered mode. + # Workers are forked web server processes. If using threads and workers together + # the concurrency of the application would be max `threads` * `workers`. + # Workers do not work on JRuby or Windows (both of which do not support + # processes). + + workers worker_count + + # Use the `preload_app!` method when specifying a `workers` number. + # This directive tells Puma to first boot the application and load code + # before forking the application. This takes advantage of Copy On Write + # process behavior so workers use less memory. + + preload_app! +end # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart