-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
WIP: Limit Thumbnail Generation Concurrency #3794
WIP: Limit Thumbnail Generation Concurrency #3794
Conversation
…t thumbnail generation processes. TODO: - [ ] Add tests/benchmarks to verify that memory consumption is lowered - [ ] Cleanup => move code related to concurrency to separate file
Without tests to show that the thumbs generation is the culprit and not the Based on what Some notes on the code:
Note that it is possible the higher memory consumption to be caused by aws/aws-sdk-go#4916. Before complicating further the implementation I suggest to prepare a test case (or at least some manual steps) that consistently trigger the issue and to start profile from there. |
Alright, let me get back to you with a benchmark or script to replicate the issue.
With limited concurrency the memory usage always stayed around I will keep digging deeper into the issue, but it is probably going to take me a few days to find the time. You cen close the PR in the mean time if you want to keep github clean. |
Co-authored-by: Tobias Muehlberger <tobias@muehlberger.dev>
I was able to experiment a little with this and can confirm that the the thumb generation or large images requires a lot of memory allocations and the the problem is not just the S3 file upload as the higher memory consumption can be examine even when only the local filesystem is used. I've performed a test locally with ~7MB 9319x5792px jpg and generating 3 different thumbs concurrently for both storage options - 100x100, 500x500 and 1000x1000. So I don't think there is much we can do (at least not easily) in this case for optimizing the memory allocations. I've pushed a slightly modified version of your PR in the I still don't exactly like the But in general, if you are still experiencing OOM errors, you can try combining the latest changes with |
This should fix the issue described in #3759. I tested this solution in my PB deployment and it did not run out of memory anymore.
This solution does not use a separate Worker-Pool, rather it just blocks the request handler if too many thumbnails are generated at the same time. I think this is the simpler approach.
It will also be easier to remove the semaphore in case this fix would be replaced by a more general solution in the new version FS abstraction (like limiting the number of open files or the number of bytes stored in memory).
The limit should probably be configurable. @ganigeorgiev do you think I should read the Env-Variable
MAX_THUMBNAIL_CONCURRENCY
?