From 0865bc55fd78edc66fb128b90d2a381c6d4dc8ff Mon Sep 17 00:00:00 2001 From: syeopite Date: Thu, 10 Apr 2025 00:42:43 -0700 Subject: [PATCH] Remove idle_pool_size config Clients created when idle_capacity is reached but not max_capacity are discarded as soon as the client is checked back into the pool, not when the connection is closed. This means that allowing idle_capacity to be lower than max_capacity essentially just makes the remaining clients a checkout timeout deterrent that gets thrown away as soon as it is used. Not useful for reusing connections whatsoever during peak load times --- config/config.example.yml | 19 ------------------- src/invidious.cr | 3 --- src/invidious/config.cr | 2 -- src/invidious/connection/pool.cr | 8 +------- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index fc9fc72e..b849c116 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -214,25 +214,6 @@ https_only: false ## #pool_size: 100 - -## -## Max idle size of the HTTP pool used to connect to youtube. Each -## domain ('youtube.com', 'ytimg.com', ...) has its own pool. -## -## This means that when releasing a connection back into the pool, it will -## be closed if there are already more than idle_pool_size connections within -## the pool -## -## Do note that idle connections are kept around forever without any way of -## timing them out. -## -## When unset this value has the same value as pool_size -## -## Accepted values: a positive integer -## Default: (internally this means that it has the same value as pool_size) -## -#idle_pool_size: - ## ## Amount of seconds to wait for a client to be free from the pool ## before raising an error diff --git a/src/invidious.cr b/src/invidious.cr index d773a6f5..e39d08c4 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -94,7 +94,6 @@ SOFTWARE = { YT_POOL = Invidious::ConnectionPool::Pool.new( max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size, timeout: CONFIG.pool_checkout_timeout ) do next make_client(YT_URL, force_resolve: true) @@ -106,7 +105,6 @@ GGPHT_URL = URI.parse("https://yt3.ggpht.com") GGPHT_POOL = Invidious::ConnectionPool::Pool.new( max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size, timeout: CONFIG.pool_checkout_timeout ) do next make_client(GGPHT_URL, force_resolve: true) @@ -114,7 +112,6 @@ end COMPANION_POOL = Invidious::ConnectionPool::Pool.new( max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size ) do companion = CONFIG.invidious_companion.sample next make_client(companion.private_url, use_http_proxy: false) diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 5304296f..d3a96cff 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -160,8 +160,6 @@ class Config # Max pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool) property pool_size : Int32 = 100 - # 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 : Float64 = 5 diff --git a/src/invidious/connection/pool.cr b/src/invidious/connection/pool.cr index 682e7cb9..b2b54f0e 100644 --- a/src/invidious/connection/pool.cr +++ b/src/invidious/connection/pool.cr @@ -7,18 +7,13 @@ module Invidious::ConnectionPool def initialize( *, max_capacity : Int32 = 5, - idle_capacity : Int32? = nil, timeout : Float64 = 5.0, &client_factory : -> HTTP::Client ) - if idle_capacity.nil? - idle_capacity = max_capacity - end - pool_options = DB::Pool::Options.new( initial_pool_size: 0, max_pool_size: max_capacity, - max_idle_pool_size: idle_capacity, + max_idle_pool_size: max_capacity, checkout_timeout: timeout ) @@ -106,7 +101,6 @@ module Invidious::ConnectionPool pool = ConnectionPool::Pool.new( max_capacity: CONFIG.pool_size, - idle_capacity: CONFIG.idle_pool_size, timeout: CONFIG.pool_checkout_timeout ) do next make_client(url, force_resolve: true)