-
Notifications
You must be signed in to change notification settings - Fork 43
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
Save image based on path to image #171
Comments
It is related to the cache dir growing? A crontab script monitoring and removing old files is one way to deal with it. Option. Could you elaborate a bit more on your perseived problem? |
Yes so i dont have problem with the disk space, but the folder itself has really big amount of files and i cant even "ls" in it. I dont need to delete old files but i would like to be able to put the cached image in the cache folder with the same structure as from the url i will try to explain again. Cache folder: /images/resized_cache/ Request uri: https://example.site/img.php?src=uploads/avatars/234234234/avatar22.png Now is saved like this: I would like to be like this: |
Ok, so you would like to configure how the structure is created in the cache dir? That could be done. I had some thoughts on this earlier but decided to stick with a flat file structure (easier to implement). From an interest, what would you gain from having this structure? Nice to have or real benefit? |
Big +1! We also have a huge cache directory (amount of files). On some servers this (huge amount of files in one single directory) could slow down things and cause problems. |
Will it be enough to use a directory structure, in the long term, or should one look into a solution where many images goes into one file (and one index-file)? One could also consider using SQLite for smaller images: Still, I would like a straight forward solution, without to much hassle. |
I think a directory structure would be the most pragmatic solution in my opinion. For my needs the directory structure would solve it! |
I think that the directory structure will work best. |
Any progress so far regarding this issue? :) My cache directory is holding 900k of files so far. I have a cronjob enabled deleting cache files older than 365 days, but the directory is still growing. Splitting the cache directory down - like mentioned above - would be super helpful! |
Not much progress, no. I checked my own cache dir and the largest only contains 5k files, not much in comparison to 900k. Nice to know we have some heavy users/usage out there. I refreshed my memory and gave it some new thougth though. I have no definitive answer for now. I need to sleep on it. |
@mosbth We are also very much in need of such a feature as well since our cache directory contains more than a million files by now. So, huge +1 from us as well. Do you have any plans on integrating the suggested feature? :) |
Plans exists yes. Then, its that thing, with time... and being able to prioritize among all other stuff one has on his magic agenda to conquer the world. The plan it to build an alternative cache-structure that mirrors the directory structure of the The directory structure will look something like this: Source image:
Cache structure:
So, each image will have its own cache directory where all its cached versions are saved. I am not sure how well this scales with a million images, but it might make it a tad easier to keep track on files in the cache directory and to get a visual overview of its content. This should also make it possible to find stray images in the cache, that is images removed/moved in the There is also the existing For those having a cache with a million files, one could guess that some kind of transfer process is needed, from old cache to new cache. So that is the current, waiting to be implemented. For stats, I looked in my largest website using cimage.
As you see, I have a pretty small cache when comparing to a million cached files. Anyway, I guess I should be real happy to see that some of you are using cimage to an extent of sites with a million cached files - that is really nice to know. Real nice. :-) |
@mosbth ah great, see things issue getting picked up! Right now we are having almost 2 (!) million files in the cache directory. It is starting to get nasty :) cache/2018/11/ Again: we are super happy with cimage serving so many image files to your users! Thank you for your great work here @mosbth ! |
@flobox @Surf-N-Code A quick question, when you say you have millions files in the cache, how many files do you have in the source @flobox Yes, a time based structure could be an alternative. I would prefer avoiding the need of creating too many sub directories. |
This is how the cache currently works, a bit simplified and excluding the usage of HTTP cache settings which further decreases the need to actually run cimage to process the request.
The obvious improvement I see is to limit the need of files in the fasttrack directory. This can be reduced to 1 json file per source image, instead of 1 file per "request string" as it is now. These files are small. The fasttrack could be implemented as a SQLite database, this limits the fasttrack files to 1 and likely adds some time for lookup. The amount of cached image files could perhaps be limited through rules allowing how to access cimage. Maybe there is some limited opportunity to reduce the number of files, when one image is the exact copy of another image, but the request url is different. This implies some more processing in cimage, or perhaps some improvement to the code. Anyway, the improvement is most likely not much. |
For general reference, I do assume that there is no actual hard limit, that we are close to reaching, even with millons of cache files, on how many files we can have in a single directory (using ext4) (source). Another conclusion from the same source is that there is no notable difference in performance, having a directory with millions of files compared or 10 files. At least, not in the way cimage is using the files in the cache dir. I'm trying to wrap my head around "why do we (really) want this", sort of asking "5 Whys" to get to the root cause of it. That feels like a good exercise before coding away... So, this far I have:
Anything to add to the list? |
@mosbth in the
You are absolutely right on this. It is just getting a little bit unwieldy with that many files in the cache directory in one directory.
Great list! Nope. Nothing to add from my side. |
Hello, is it possible to save the images based on the requested path to them?
My cache folder started to grow really big.
Example:
https://example.site/img.php?src=uploads/avatars/234234234/avatar22.png
Cache path should be:
/images/cache/uploads/avatars/234234234/avatar22-cached-picture-something-234234.png
The text was updated successfully, but these errors were encountered: