Skip to content

Commit 70ff778

Browse files
committed
[ruby/puma] Use same number of connections as threads
When using puma use the same amount of connections as threads. For other servers default to 512.
1 parent 6394199 commit 70ff778

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

frameworks/Ruby/rack-sequel/boot.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def connect(dbtype)
2121

2222
# Determine threading/thread pool size and timeout
2323
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
24-
opts[:max_connections] = (2 * Math.log(threads)).floor
24+
opts[:max_connections] = threads
2525
opts[:pool_timeout] = 10
26+
else
27+
opts[:max_connections] = 512
2628
end
2729

2830
Sequel.connect \

frameworks/Ruby/sinatra-sequel/boot.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def connect(dbtype)
2828

2929
# Determine threading/thread pool size and timeout
3030
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
31-
opts[:max_connections] = (2 * Math.log(threads)).floor
31+
opts[:max_connections] = threads
3232
opts[:pool_timeout] = 10
33+
else
34+
opts[:max_connections] = 512
3335
end
3436

3537
Sequel.connect \

frameworks/Ruby/sinatra/boot.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ def connect(dbtype)
3333

3434
# Determine threading/thread pool size and timeout
3535
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
36-
opts[:pool] = (2 * Math.log(threads)).floor
36+
opts[:pool] = threads
3737
opts[:checkout_timeout] = 10
3838
else
39-
# TODO: ActiveRecord doesn't have a single-threaded mode?
40-
opts[:pool] = 1
41-
opts[:checkout_timeout] = 0
39+
opts[:pool] = 512
4240
end
4341

4442
ActiveRecord::Base.establish_connection(opts)

0 commit comments

Comments
 (0)