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
High CPU usage in "Update all Episode Subtitles from disk" task #1916
Comments
What kind of hardware are we talking about here? I don't see a bug here, only the perception that CPU usage is too high. |
Does one of these open each and every media file and index the properties and embedded subtitles? The answer is no. It takes 1m30s to scan 3500 episodes on my setup. You can run this job less often if it bother you but there's nothing I can do about this. |
Please be polite. I am spending my time trying to improve your software. |
Sorry, I didn't meant to be impolite.
This is exactly what we do by caching ffprobe output until the episode id from Sonarr or the file size change. I'll look at the code again in the upcoming days to see if something can be improved. |
Thank you. File size is ok, but it's not as reliable as the modification date or the hash. I'm pretty sure you will find you are doing more than comparing the file size. I don't know how how are handling the migration when the user updates Bazarr version. In that case you should invalidate the cache (by setting a wrong hash in all subtitles in the database) that will force a complete scan just in case a newer version of ffmpeg provides different info. |
I'm running into this too - it's a problem. A 36 thread CPU @ 5GHz being consumed across all threads 90-100% for 5 minutes isn't acceptable, even if it's doing legitimate work. Possible solutions I see are:
From reading the above it seems like the task is not critical and it wouldn't be a problem for it to take extra time. |
@morpheus65535 I looked at the code.
How to reproduce:
Solution:
save
Expected result: |
I don't know what's causing all those thread but the indexing task is sequential: it will run one episode after another in a single thread. If required, it will start a thread for ffprobe and wait for the process to return before going to the next one. The worst case scenario is having one thread for the indexing process and a sub process for ffprobe. I don't say you don't have an issue but it's not related to the indexing process. |
Sounds like a good idea, I'll see how I can implement this because, actually, we don't care about the previously index subtitles. We simply reindex all of them. I'll try to work on this in the upcoming week. Thanks for the investigation! |
@ngosang I've implemented your suggestion. I don't know if you'll really get some benefit out of that. You can try the upcoming beta and let me know. |
@morpheus65535 thank you. it's working in most cases but there is a bug. I opened a PR, it's tested by me but feel free to improve the code. => #1926 First iteration:
Second iteration:
The first subtitle is missing because you "continue" and return a subtitle with None language. In the third iteration the subtitle is discovered again using CPU... and the process repeats. |
@ngosang thanks for this one! I've worked on that for too many night and I've lost track of what was done and missing. The PR seems to be good. I don't see any improvement on my side but all of my subtitles include language code so it's to be expected. I'll merge your PR in a couple of minutes. I'll let you close this issue if it's good enough for you. Thanks again! |
Good improvement! |
Describe the bug
High CPU usage in "Update all Episode Subtitles from disk" task
To Reproduce
The task "Update all Episode Subtitles from disk" is launched everyday at 4:00
As you can see in the screenshot it takes 14 minutes and uses 100% of the CPU. The system is a RaspberryPi but that is a lot of CPU...
I have 1556 episodes, you can guess I have 5000 subs approx.
Expected behavior
Reduce the CPU usage and the scan time.
Screenshots
Logs
Software (please complete the following information):
Additional context
.
The text was updated successfully, but these errors were encountered: