1
+ # frozen_string_literal: true
2
+
3
+ # Specifies the number of `workers` to boot in clustered mode.
4
+ # Workers are forked webserver processes. If using threads and workers together
5
+ # the concurrency of the application would be max `threads` * `workers`.
6
+ # Workers do not work on JRuby or Windows (both of which do not support
7
+ # processes).
8
+ #
9
+ workers ENV . fetch ( 'WEB_CONCURRENCY' ) { 2 }
10
+
1
11
# Puma can serve each request in a thread from an internal thread pool.
2
12
# The `threads` method setting takes two numbers a minimum and maximum.
3
13
# Any libraries that use thread pools should be configured to match
4
14
# the maximum value specified for Puma. Default is set to 5 threads for minimum
5
15
# and maximum, this matches the default thread size of Active Record.
6
16
#
7
- threads_count = ENV . fetch ( " RAILS_MAX_THREADS" ) { 5 } . to_i
17
+ threads_count = ENV . fetch ( ' RAILS_MAX_THREADS' ) { 5 }
8
18
threads threads_count , threads_count
9
19
10
20
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11
21
#
12
- port ENV . fetch ( " PORT" ) { 3000 }
22
+ port ENV . fetch ( ' PORT' ) { 3000 }
13
23
14
24
# Specifies the `environment` that Puma will run in.
15
25
#
16
- environment ENV . fetch ( "RAILS_ENV" ) { "development" }
17
-
18
- # Specifies the number of `workers` to boot in clustered mode.
19
- # Workers are forked webserver processes. If using threads and workers together
20
- # the concurrency of the application would be max `threads` * `workers`.
21
- # Workers do not work on JRuby or Windows (both of which do not support
22
- # processes).
23
- #
24
- # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
26
+ environment ENV . fetch ( 'RACK_ENV' ) { 'development' }
25
27
26
28
# Use the `preload_app!` method when specifying a `workers` number.
27
29
# This directive tells Puma to first boot the application and load code
30
32
# you need to make sure to reconnect any threads in the `on_worker_boot`
31
33
# block.
32
34
#
33
- # preload_app!
35
+ preload_app!
34
36
35
37
# The code in the `on_worker_boot` will be called if you are using
36
38
# clustered mode by specifying a number of `workers`. After each worker
39
41
# or connections that may have been created at application boot, Ruby
40
42
# cannot share connections between processes.
41
43
#
42
- # on_worker_boot do
43
- # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
- # end
44
+ on_worker_boot do
45
+ # Worker specific setup for Rails 4.1+
46
+ # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
47
+ ActiveRecord ::Base . establish_connection
48
+ end
45
49
46
50
# Allow puma to be restarted by `rails restart` command.
47
- plugin :tmp_restart
51
+ plugin :tmp_restart
0 commit comments