瀏覽代碼

[ruby/puma] Use same number of connections as threads (#10108)

When using puma use the same amount of connections as threads.
For other servers default to 512.
Petrik de Heus 1 天之前
父節點
當前提交
c890b86e0d

+ 1 - 1
frameworks/Ruby/padrino/config/database.rb

@@ -9,7 +9,7 @@ opts = {
 
 # Determine threading/thread pool size and timeout
 if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-  opts[:pool] = (2 * Math.log(threads)).floor
+  opts[:pool] = threads
   opts[:checkout_timeout] = 10
 else
   # TODO: ActiveRecord doesn't have a single-threaded mode?

+ 3 - 1
frameworks/Ruby/rack-sequel/boot.rb

@@ -21,8 +21,10 @@ def connect(dbtype)
 
   # Determine threading/thread pool size and timeout
   if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = (2 * Math.log(threads)).floor
+    opts[:max_connections] = threads
     opts[:pool_timeout] = 10
+  else
+    opts[:max_connections] = 512
   end
 
   Sequel.connect \

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

@@ -36,8 +36,10 @@ def connect(dbtype)
   # Determine threading/thread pool size and timeout
   if defined?(Puma) &&
         (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = (2 * Math.log(threads)).floor
+    opts[:max_connections] = threads
     opts[:pool_timeout] = 10
+  else
+    opts[:max_connections] = 512
   end
 
   Sequel.connect "%{adapter}://%{host}/%{database}?user=%{user}&password=%{password}" %

+ 3 - 1
frameworks/Ruby/sinatra-sequel/boot.rb

@@ -28,8 +28,10 @@ def connect(dbtype)
 
   # Determine threading/thread pool size and timeout
   if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:max_connections] = (2 * Math.log(threads)).floor
+    opts[:max_connections] = threads
     opts[:pool_timeout] = 10
+  else
+    opts[:max_connections] = 512
   end
 
   Sequel.connect \

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

@@ -33,12 +33,10 @@ def connect(dbtype)
 
   # Determine threading/thread pool size and timeout
   if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
-    opts[:pool] = (2 * Math.log(threads)).floor
+    opts[:pool] = threads
     opts[:checkout_timeout] = 10
   else
-    # TODO: ActiveRecord doesn't have a single-threaded mode?
-    opts[:pool] = 1
-    opts[:checkout_timeout] = 0
+    opts[:pool] = 512
   end
 
   ActiveRecord::Base.establish_connection(opts)