[Enhancement] Add rate limiting to yt-dlp requests; prevent saving Media Items when throttled by YouTube #559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's new?
On rate limiting
This isn't the approach I wanted to use, but it seems to work well enough. I tried several other things first with no luck:
sleep
to the end of each yt-dlp-related jobWhat I finally ended up doing is simply integrating yt-dlp's sleep-related arguments into every command (provided the user sets a sleep interval). This still doesn't account for job runner concurrency, but when I started profiling requests, it became clear to me that FAR more HTTP requests happen in a single yt-dlp command than I had expected. If the metric to look for is sheer volume of requests then this appears to be the most impactful approach by far.
It's not clear to me whether this is the only change I'll need to make or if I'll have to also integrate some other rate limiting approach, but it's a start!
This approach sleeps between every request which will massively slow down your yt-dlp operations, especially if you're downloading dozens of subtitle languages per-video. Start conservatively here by setting your Sleep Interval to 5-ish seconds. Feel free to ramp up or down from there depending on how that goes.
What's changed?
N/A
What's fixed?
N/A
Any other comments?
N/A