-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor connection pool #5081
base: master
Are you sure you want to change the base?
Refactor connection pool #5081
Conversation
- Raises a wrapped exception on any DB:Error - Don't use a non-pool client when client fails - Ensure that client is always released
pool.checkout(&block) already ensures that the checked out item will be released back into the pool
TODO: Add connection pool stats to https://crystal-lang.github.io/crystal-db/api/0.13.1/DB/Pool.html#stats-instance-method |
src/invidious/config.cr
Outdated
property idle_pool_size : Int32? = nil | ||
|
||
# Amount of seconds to wait for a client to be free from the pool before rasing an error | ||
property pool_checkout_timeout : Int32 = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oddly, the Crystal compiler didn't complain: there is a type mismatch between this property (Int32
) and Pool.timeout
(Float64
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I didn't notice that
But I think that's an intended feature of Crystal. The compiler allows you to use an integer in place of a float but not the other way around.
The streaming API of HTTP::Client has an internal buffer that will continue to persist onto the next request unless the response is fully read. This commit privatizes the #client method of Pool and instead expose various HTTP request methods that will call and yield the underlying request and response. This way, we can ensure that the resposne is fully read before the client is passed back into the pool for another request.
@pool.release should not be called when the client has already been deleted from the pool.
Make non-block request method internally call the block based request method.
Brings improvements from https://github.com/jgaskins/http_client which is a shard that implements a HTTP connection pool through
DB::Pool
like Invidious.The most noticeable change is that connection timeout errors will no longer say
DB::PoolTimeout
but ratherInvidious::ConnectionPool::Error
. Full backtrace here.Backtrace
I've also added a configuration option to customize max idle pool size and the checkout timeout