Skip to content

Commit a775dce

Browse files
authored
[ruby] Hardcode Puma to 5 threads (#10381)
5 threads is recommended, this also makes sure results are more predictable when run on different environments.
1 parent b0ad9a3 commit a775dce

19 files changed

+44
-57
lines changed

frameworks/Ruby/rack-sequel/boot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def connect(dbtype)
2020
end
2121

2222
# Determine threading/thread pool size and timeout
23-
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
24-
opts[:max_connections] = threads
23+
if defined?(Puma)
24+
opts[:max_connections] = ENV.fetch('MAX_THREADS')
2525
opts[:pool_timeout] = 10
2626
else
2727
opts[:max_connections] = 512

frameworks/Ruby/rack-sequel/config/mri_puma.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
before_fork do
2+
Sequel::DATABASES.each(&:disconnect)
3+
end

frameworks/Ruby/rack-sequel/rack-sequel-postgres.dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
1717
ENV DBTYPE=postgresql
1818

1919
ENV WEB_CONCURRENCY=auto
20+
ENV MAX_THREADS=5
21+
2022
EXPOSE 8080
2123

22-
CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production
24+
CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production

frameworks/Ruby/rack-sequel/rack-sequel.dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
1717
ENV DBTYPE=mysql
1818

1919
ENV WEB_CONCURRENCY=auto
20+
ENV MAX_THREADS=5
21+
2022
EXPOSE 8080
2123

22-
CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production
24+
CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production

frameworks/Ruby/roda-sequel/boot.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def connect(dbtype)
3434
end
3535

3636
# Determine threading/thread pool size and timeout
37-
if defined?(Puma) &&
38-
(threads = Puma.cli_config.options.fetch(:max_threads)) > 1
39-
opts[:max_connections] = threads
37+
if defined?(Puma)
38+
opts[:max_connections] = ENV.fetch('MAX_THREADS')
4039
opts[:pool_timeout] = 10
4140
else
4241
opts[:max_connections] = 512

frameworks/Ruby/roda-sequel/config/mri_puma.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
before_fork do
2+
Sequel::DATABASES.each(&:disconnect)
3+
end

frameworks/Ruby/roda-sequel/roda-sequel-postgres.dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ RUN bundle install --jobs=8
1717
ENV RACK_ENV=production
1818
ENV DBTYPE=postgresql
1919

20+
ENV MAX_THREADS=5
2021
ENV WEB_CONCURRENCY=auto
22+
2123
EXPOSE 8080
2224

23-
CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
25+
CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

frameworks/Ruby/roda-sequel/roda-sequel.dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ ENV RACK_ENV=production
1818
ENV DBTYPE=mysql
1919

2020
ENV WEB_CONCURRENCY=auto
21+
ENV MAX_THREADS=5
22+
2123
EXPOSE 8080
2224

23-
CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
25+
CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

0 commit comments

Comments
 (0)