Created
January 26, 2023 15:56
-
-
Save benoittgt/86f39c7348ad5a50165c7362e450a541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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