Skip to content

Instantly share code, notes, and snippets.

@benoittgt
Created January 26, 2023 15:56
Show Gist options
  • Select an option

  • Save benoittgt/86f39c7348ad5a50165c7362e450a541 to your computer and use it in GitHub Desktop.

Select an option

Save benoittgt/86f39c7348ad5a50165c7362e450a541 to your computer and use it in GitHub Desktop.
def self.checkout_max_connections(role:)
threads = []
before = nil
after = nil
pool_size = nil
base_connection_class.connected_to(role: role) do
before = connection_pool.stat
pool_size = connection_pool.size
end
pool_size.times do
threads << Thread.new {
# NOTE(BF): since connected_to is thread-safe, need to make
# threads outside of it
checkout_connection(role: role)
}
end
threads.each(&:join)
base_connection_class.connected_to(role: role) do
after = connection_pool.stat
end
{
size: pool_size,
before: before,
after: after,
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment