Skip to content
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

Use connection pools when requesting images from YouTube #4326

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

syeopite
Copy link
Member

@syeopite syeopite commented Dec 9, 2023

Theoretically this should improve memory usage and performance by quite a bit as we aren't creating a new HTTP::Client and in a turn a new connection for every image we request from YouTube.

This should be tested extensively, especially in IPv6 only environment.

Closes #4009

@syeopite syeopite requested a review from a team as a code owner December 9, 2023 02:46
@syeopite syeopite requested review from unixfox and removed request for a team December 9, 2023 02:46
@unixfox
Copy link
Member

unixfox commented Dec 18, 2023

Can't test as I have an external proxy for that. But sounds good

src/invidious.cr Outdated Show resolved Hide resolved
return pool
else
LOGGER.info("ytimg_pool: Creating a new HTTP pool for \"https://#{subdomain}.ytimg.com\"")
pool = YoutubeConnectionPool.new(URI.parse("https://#{subdomain}.ytimg.com"), capacity: CONFIG.pool_size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about keeping that many open connections on small instances. Maybe we could bypass the pooling system if CONFIG.pool_size == 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the pool not automatically clean up connections?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so? It seems that released connections are pushed to the idle list, but I'm not sure what causes them to be closed:
https://github.com/crystal-lang/crystal-db/blob/3eaac85a5d4b7bee565b55dcb584e84e29fc5567/src/db/pool.cr#L151-L185

Copy link
Member Author

@syeopite syeopite Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's a problem...

Regarding the bypass though, shouldn't that already be what DB:Pool does when pool_size equals 0? Invidious seems to be able to handle requests fine when CONFIG.pool_size is set to zero at least

src/invidious/routes/images.cr Show resolved Hide resolved
src/invidious/routes/images.cr Show resolved Hide resolved
@syeopite
Copy link
Member Author

syeopite commented Jan 8, 2024

I wonder if something similar to get_ytimg_pool should also be used for all the googlevideo requests. We should probably be reducing all these one-off clients Invidious creates.

src/invidious/routes/images.cr Outdated Show resolved Hide resolved
src/invidious/routes/images.cr Outdated Show resolved Hide resolved
@github-actions github-actions bot added the stale label Apr 10, 2024
@SamantazFox SamantazFox removed the stale label Apr 20, 2024
@iv-org iv-org deleted a comment from github-actions bot Apr 20, 2024
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
@SamantazFox
Copy link
Member

I wonder if something similar to get_ytimg_pool should also be used for all the googlevideo requests. We should probably be reducing all these one-off clients Invidious creates.

It would have to be somewhat different. There are so many video servers that keeping connections pools to every single one would be wasteful. But keeping the connection open per client (= almost for each video) would be nice, though I have no idea how to do that efficiently....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Consider using pools for the various image requests to YouTube
3 participants