From 07caf93fbd11f5a80c752cc41ee6585d00987eac Mon Sep 17 00:00:00 2001 From: syeopite Date: Mon, 11 Nov 2024 16:26:58 -0800 Subject: [PATCH] Add config to set connection pool checkout timeout --- config/config.example.yml | 13 +++++++++++-- src/invidious.cr | 10 ++++++++-- src/invidious/config.cr | 3 +++ src/invidious/connection/pool.cr | 3 ++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 13bb634e..85c27be1 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -155,7 +155,7 @@ https_only: false ## -## Idle size of the HTTP pool used to connect to youtube. Each +## Max idle size of the HTTP pool used to connect to youtube. Each ## domain ('youtube.com', 'ytimg.com', ...) has its own pool. ## ## When unset this value has the same value as pool_size @@ -163,8 +163,17 @@ https_only: false ## Accepted values: a positive integer ## Default: (internally this means that it has the same value as pool_size) ## -#idle pool_size: 100 +#idle_pool_size: 100 +## +## Amount of seconds to wait for a client to be free from the pool +## before raising an error +## +## +## Accepted values: a positive integer +## Default: 5 +## +#pool_checkout_timeout: 5 ## diff --git a/src/invidious.cr b/src/invidious.cr index 189cde40..8884b935 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -92,14 +92,20 @@ SOFTWARE = { "branch" => "#{CURRENT_BRANCH}", } -YT_POOL = Invidious::ConnectionPool::Pool.new(YT_URL, max_capacity: CONFIG.pool_size, idle_capacity: CONFIG.idle_pool_size) +YT_POOL = Invidious::ConnectionPool::Pool.new( + YT_URL, + max_capacity: CONFIG.pool_size, + idle_capacity: CONFIG.idle_pool_size, + timeout: CONFIG.pool_checkout_timeout +) # Image request pool GGPHT_POOL = Invidious::ConnectionPool::Pool.new( URI.parse("https://yt3.ggpht.com"), max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size + idle_capacity: CONFIG.idle_pool_size, + timeout: CONFIG.pool_checkout_timeout ) # CLI diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 9eace656..a0105af8 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -144,6 +144,9 @@ class Config # Idle pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool) 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 + # HTTP Proxy configuration property http_proxy : HTTPProxyConfig? = nil diff --git a/src/invidious/connection/pool.cr b/src/invidious/connection/pool.cr index a3a5935f..cf5a918a 100644 --- a/src/invidious/connection/pool.cr +++ b/src/invidious/connection/pool.cr @@ -79,7 +79,8 @@ module Invidious::ConnectionPool pool = Invidious::ConnectionPool::Pool.new( URI.parse("https://#{subdomain}.ytimg.com"), max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size + idle_capacity: CONFIG.idle_pool_size, + timeout: CONFIG.pool_checkout_timeout ) YTIMG_POOLS[subdomain] = pool