Skip to content

Commit 1920f21

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 1920f21

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
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/roda-sequel/boot.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ def connect(dbtype)
3636
# Determine threading/thread pool size and timeout
3737
if defined?(Puma) &&
3838
(threads = Puma.cli_config.options.fetch(:max_threads)) > 1
39-
opts[:max_connections] = (2 * Math.log(threads)).floor
39+
opts[:max_connections] = threads
4040
opts[:pool_timeout] = 10
41+
else
42+
opts[:max_connections] = 512
4143
end
4244

4345
Sequel.connect "%{adapter}://%{host}/%{database}?user=%{user}&password=%{password}" %

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)