Skip to content

Commit b219440

Browse files
committed
Enable clustered mode in production
1 parent c0b800c commit b219440

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

.github/workflows/benchmark.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ on:
3434
required: false
3535
default: 'fortio,vegeta,k6'
3636
type: string
37+
web_concurrency:
38+
description: 'Number of Puma worker processes'
39+
required: false
40+
default: 2
41+
type: number
3742
push:
3843
branches:
3944
- master
@@ -49,6 +54,7 @@ env:
4954
REQUEST_TIMEOUT: ${{ github.event.inputs.request_timeout || '60s' }}
5055
VUS: ${{ github.event.inputs.vus || '100' }}
5156
TOOLS: ${{ github.event.inputs.tools || 'fortio,vegeta,k6' }}
57+
WEB_CONCURRENCY: ${{ github.event.inputs.web_concurrency || '2' }}
5258

5359
jobs:
5460
benchmark:
@@ -254,8 +260,10 @@ jobs:
254260
echo "Benchmark parameters:"
255261
echo " - RATE: ${RATE}"
256262
echo " - DURATION_SEC: ${DURATION_SEC}"
263+
echo " - REQUEST_TIMEOUT: ${REQUEST_TIMEOUT}"
257264
echo " - VUS: ${VUS}"
258265
echo " - TOOLS: ${TOOLS}"
266+
echo " - WEB_CONCURRENCY: ${WEB_CONCURRENCY}"
259267
echo ""
260268
261269
if ! spec/performance/bench.sh; then

spec/dummy/config/puma.rb

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,45 @@
1010
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
1111
threads min_threads_count, max_threads_count
1212

13+
rails_env = ENV.fetch("RAILS_ENV", "development")
14+
1315
# Specifies the `worker_timeout` threshold that Puma will use to wait before
1416
# terminating a worker in development environments.
1517
#
16-
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
18+
worker_timeout 3600 if rails_env == "development"
1719

1820
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
1921
#
2022
port ENV.fetch("PORT", 3000)
2123

2224
# Specifies the `environment` that Puma will run in.
2325
#
24-
environment ENV.fetch("RAILS_ENV", "development")
26+
environment rails_env
2527

2628
# Specifies the `pidfile` that Puma will use.
2729
pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid")
2830

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 }
36-
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 rails_env == "production"
32+
# Specifies the number of `workers` to boot in clustered mode.
33+
# Workers are forked web server processes. If using threads and workers together
34+
# the concurrency of the application would be max `threads` * `workers`.
35+
# Workers do not work on JRuby or Windows (both of which do not support
36+
# processes).
37+
#
38+
workers ENV.fetch("WEB_CONCURRENCY", 2)
39+
40+
# Use the `preload_app!` method when specifying a `workers` number.
41+
# This directive tells Puma to first boot the application and load code
42+
# before forking the application. This takes advantage of Copy On Write
43+
# process behavior so workers use less memory.
44+
#
45+
preload_app!
46+
47+
# Specifies the `worker_shutdown_timeout` threshold that Puma will use to wait before
48+
# terminating a worker.
49+
#
50+
worker_shutdown_timeout 60
51+
end
4352

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

0 commit comments

Comments
 (0)