Skip to content

Commit

Permalink
[ruby/rack] Use autotune for database connections
Browse files Browse the repository at this point in the history
  • Loading branch information
p8 committed Nov 10, 2023
1 parent 7471784 commit 32a3914
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frameworks/Ruby/rack/config/auto_tune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'etc'

KB_PER_WORKER = 128 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k)
MIN_WORKERS = 15
MIN_WORKERS = 2
MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical
MIN_THREADS_PER_WORKER = 1
MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256)
Expand Down
9 changes: 7 additions & 2 deletions frameworks/Ruby/rack/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ class HelloWorld
</html>'

def initialize
# auto_tune
max_connections = 512
if defined?(Puma)
max_connections = auto_tune.reduce(:*)
elsif defined?(Unicorn)
max_connections, = auto_tune
else
max_connections = 512
end
@db = PgDb.new(DEFAULT_DATABASE_URL, max_connections)
end

Expand Down

0 comments on commit 32a3914

Please sign in to comment.