Browse Source

[ruby] Hardcode Puma to 5 threads (#10381)

5 threads is recommended, this also makes sure results are more
predictable when run on different environments.
Petrik de Heus 6 days ago
parent
commit
a775dce2e4

+ 2 - 2
frameworks/Ruby/rack-sequel/boot.rb

@@ -20,8 +20,8 @@ def connect(dbtype)
   end
 
   # Determine threading/thread pool size and timeout
-  if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = threads
+  if defined?(Puma)
+    opts[:max_connections] = ENV.fetch('MAX_THREADS')
     opts[:pool_timeout] = 10
   else
     opts[:max_connections] = 512

+ 0 - 10
frameworks/Ruby/rack-sequel/config/mri_puma.rb

@@ -1,10 +0,0 @@
-require_relative 'auto_tune'
-
-# FWBM only... use the puma_auto_tune gem in production!
-_, num_threads = auto_tune
-
-threads num_threads, num_threads
-
-before_fork do
-  Sequel::DATABASES.each(&:disconnect)
-end

+ 3 - 0
frameworks/Ruby/rack-sequel/config/puma.rb

@@ -0,0 +1,3 @@
+before_fork do
+  Sequel::DATABASES.each(&:disconnect)
+end

+ 3 - 1
frameworks/Ruby/rack-sequel/rack-sequel-postgres.dockerfile

@@ -17,6 +17,8 @@ RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 ENV DBTYPE=postgresql
 
 ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production

+ 3 - 1
frameworks/Ruby/rack-sequel/rack-sequel.dockerfile

@@ -17,6 +17,8 @@ RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 ENV DBTYPE=mysql
 
 ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production

+ 2 - 3
frameworks/Ruby/roda-sequel/boot.rb

@@ -34,9 +34,8 @@ def connect(dbtype)
   end
 
   # Determine threading/thread pool size and timeout
-  if defined?(Puma) &&
-        (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = threads
+  if defined?(Puma)
+    opts[:max_connections] = ENV.fetch('MAX_THREADS')
     opts[:pool_timeout] = 10
   else
     opts[:max_connections] = 512

+ 0 - 10
frameworks/Ruby/roda-sequel/config/mri_puma.rb

@@ -1,10 +0,0 @@
-require_relative 'auto_tune'
-
-# FWBM only... use the puma_auto_tune gem in production!
-_, num_threads = auto_tune
-
-threads num_threads
-
-before_fork do
-  Sequel::DATABASES.each(&:disconnect)
-end

+ 3 - 0
frameworks/Ruby/roda-sequel/config/puma.rb

@@ -0,0 +1,3 @@
+before_fork do
+  Sequel::DATABASES.each(&:disconnect)
+end

+ 3 - 1
frameworks/Ruby/roda-sequel/roda-sequel-postgres.dockerfile

@@ -17,7 +17,9 @@ RUN bundle install --jobs=8
 ENV RACK_ENV=production
 ENV DBTYPE=postgresql
 
+ENV MAX_THREADS=5
 ENV WEB_CONCURRENCY=auto
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

+ 3 - 1
frameworks/Ruby/roda-sequel/roda-sequel.dockerfile

@@ -18,6 +18,8 @@ ENV RACK_ENV=production
 ENV DBTYPE=mysql
 
 ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

+ 2 - 2
frameworks/Ruby/sinatra-sequel/boot.rb

@@ -27,8 +27,8 @@ def connect(dbtype)
   end
 
   # Determine threading/thread pool size and timeout
-  if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = threads
+  if defined?(Puma)
+    opts[:max_connections] = ENV.fetch('MAX_THREADS')
     opts[:pool_timeout] = 10
   else
     opts[:max_connections] = 512

+ 0 - 10
frameworks/Ruby/sinatra-sequel/config/mri_puma.rb

@@ -1,10 +0,0 @@
-require_relative 'auto_tune'
-
-# FWBM only... use the puma_auto_tune gem in production!
-_, num_threads = auto_tune
-
-threads num_threads
-
-before_fork do
-  Sequel::DATABASES.each(&:disconnect)
-end

+ 3 - 0
frameworks/Ruby/sinatra-sequel/config/puma.rb

@@ -0,0 +1,3 @@
+before_fork do
+  Sequel::DATABASES.each(&:disconnect)
+end

+ 4 - 2
frameworks/Ruby/sinatra-sequel/sinatra-sequel-postgres.dockerfile

@@ -13,10 +13,12 @@ WORKDIR /sinatra-sequel
 ENV BUNDLE_WITH=postgresql:puma
 RUN bundle install --jobs=4 --gemfile=/sinatra-sequel/Gemfile
 
-ENV WEB_CONCURRENCY=auto
 ENV APP_ENV=production
 ENV DBTYPE=postgresql
 
+ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

+ 4 - 2
frameworks/Ruby/sinatra-sequel/sinatra-sequel.dockerfile

@@ -13,10 +13,12 @@ WORKDIR /sinatra-sequel
 ENV BUNDLE_WITH=mysql:puma
 RUN bundle install --jobs=4 --gemfile=/sinatra-sequel/Gemfile
 
-ENV WEB_CONCURRENCY=auto
 ENV APP_ENV=production
 ENV DBTYPE=mysql
 
+ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080

+ 2 - 3
frameworks/Ruby/sinatra/boot.rb

@@ -30,10 +30,9 @@ def connect(dbtype)
     opts[:adapter] = 'postgresql'
   end
 
-
   # Determine threading/thread pool size and timeout
-  if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:pool] = threads
+  if defined?(Puma)
+    opts[:pool] = ENV.fetch('MAX_THREADS')
     opts[:checkout_timeout] = 10
   else
     opts[:pool] = 512

+ 0 - 6
frameworks/Ruby/sinatra/config/puma.rb

@@ -1,6 +0,0 @@
-require_relative 'auto_tune'
-
-# FWBM only... use the puma_auto_tune gem in production!
-_, num_threads = auto_tune
-
-threads num_threads, num_threads

+ 4 - 2
frameworks/Ruby/sinatra/sinatra-postgres.dockerfile

@@ -13,10 +13,12 @@ WORKDIR /sinatra
 ENV BUNDLE_WITH=postgresql:puma
 RUN bundle install --jobs=4 --gemfile=/sinatra/Gemfile
 
-ENV WEB_CONCURRENCY=auto
 ENV APP_ENV=production
 ENV DBTYPE=postgresql
 
+ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -b tcp://0.0.0.0:8080

+ 3 - 1
frameworks/Ruby/sinatra/sinatra.dockerfile

@@ -17,6 +17,8 @@ ENV APP_ENV=production
 ENV DBTYPE=mysql
 
 ENV WEB_CONCURRENCY=auto
+ENV MAX_THREADS=5
+
 EXPOSE 8080
 
-CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080
+CMD bundle exec puma -b tcp://0.0.0.0:8080