Jelajahi Sumber

[ruby/rack] Let Puma decide the number of workers (#10117)

Petrik de Heus 2 hari lalu
induk
melakukan
9c1868ee0b

+ 6 - 12
frameworks/Ruby/rack/config/puma.rb

@@ -1,21 +1,15 @@
-# frozen_string_literal: true
-
 require_relative 'auto_tune'
-require 'etc'
-require 'sequel'
 
 # FWBM only... use the puma_auto_tune gem in production!
-num_workers, num_threads = auto_tune
-num_threads = [num_threads, 32].min
-
-before_fork do
-  Sequel::DATABASES.each(&:disconnect)
-end
+_, num_threads = auto_tune
 
 if RUBY_PLATFORM == 'java'
   num_threads = 512
   num_workers = 0
 end
 
-workers num_workers
-threads num_threads, num_threads
+threads num_threads
+
+before_fork do
+  Sequel::DATABASES.each(&:disconnect)
+end

+ 2 - 4
frameworks/Ruby/rack/hello_world.rb

@@ -42,10 +42,8 @@ class HelloWorld
   </html>'
 
   def initialize
-    if defined?(Puma)
-      num_workers, num_threads = auto_tune
-      num_threads = [num_threads, 32].min
-      max_connections = num_workers * num_threads
+    if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
+      max_connections = threads
     else
       max_connections = 512
     end

+ 1 - 0
frameworks/Ruby/rack/rack.dockerfile

@@ -19,5 +19,6 @@ RUN bundle install --jobs=8
 COPY . .
 
 EXPOSE 8080
+ENV WEB_CONCURRENCY=auto
 
 CMD bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:8080 -e production