Skip to content

Commit 7dc9ae5

Browse files
committed
[ruby/rack] Let Puma decide the number of workers
1 parent ea7463a commit 7dc9ae5

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
# frozen_string_literal: true
2-
31
require_relative 'auto_tune'
4-
require 'etc'
5-
require 'sequel'
62

73
# FWBM only... use the puma_auto_tune gem in production!
8-
num_workers, num_threads = auto_tune
9-
num_threads = [num_threads, 32].min
10-
11-
before_fork do
12-
Sequel::DATABASES.each(&:disconnect)
13-
end
4+
_, num_threads = auto_tune
145

156
if RUBY_PLATFORM == 'java'
167
num_threads = 512
178
num_workers = 0
189
end
1910

20-
workers num_workers
21-
threads num_threads, num_threads
11+
threads num_threads
12+
13+
before_fork do
14+
Sequel::DATABASES.each(&:disconnect)
15+
end

frameworks/Ruby/rack/hello_world.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ class HelloWorld
4242
</html>'
4343

4444
def initialize
45-
if defined?(Puma)
46-
num_workers, num_threads = auto_tune
47-
num_threads = [num_threads, 32].min
48-
max_connections = num_workers * num_threads
45+
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
46+
max_connections = threads
4947
else
5048
max_connections = 512
5149
end

frameworks/Ruby/rack/rack.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ RUN bundle install --jobs=8
1919
COPY . .
2020

2121
EXPOSE 8080
22+
ENV WEB_CONCURRENCY=auto
2223

2324
CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production

0 commit comments

Comments
 (0)