Memory‑vs‑Disk Trade‑Off: LiipImagine Bundle Cache Backend for Sulu Asset Management
0 reputation · 24 Apr 2020, 01:29 UTC
0 reputation · 24 Apr 2020, 01:29 UTC
Determine the optimal cache strategy for on‑the‑fly image transformations in Sulu’s Asset Management module.
Should the cache be kept in memory to prioritize speed for small assets, or switched to a file‑based cache to conserve RAM in constrained environments?
For a typical Sulu deployment using LiipImagineBundle:
ImagineCache::remove for the asset’s filter variants.If your container enforces a strict RAM ceiling (e.g., < 500 MiB per pod) and you expect more than a few hundred distinct image variants, start with the filesystem cache to keep memory usage predictable. Monitor worker RSS and cache hit ratio; only switch to the array cache if you measure that the extra latency from disk I/O is unacceptable and you have sufficient headroom for per‑worker memory duplication.
php bin/console debug:container --parameter liip_imagine.cache.callable (or inspect config/packages/liip_imagine.yaml).symfony console cache:pool:stats to record hit/miss ratios and average get/set times for both backends.ps -o rss,pid -C php-fpm).Missing diagnostic detail that would change the recommendation: Please provide the average number of distinct filter variants per asset and the typical size of the original assets (or the average transformed binary size). This lets us estimate the per‑worker memory footprint of the array cache and decide whether it fits within your RAM budget.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 24 Apr 2020, 06:12 UTC
A critical detail when choosing the ArrayAdapter is that it is local to the PHP process. In a PHP-FPM environment, the cache is not shared; if you have 10 workers, the same transformed image may be stored 10 times across your RAM. Furthermore, binary data handled within PHP often carries overhead that can make the memory footprint larger than the resulting file size on disk.
In containers with strict limits (e.g., <512 MiB), this duplication can lead to Out-of-Memory (OOM) kills before the application reaches its configured memory_limit, as the aggregate usage of all FPM workers exceeds the container's cgroup limit.
To quantify this impact, you can use memory_get_usage() during a request cycle to observe the growth of the array cache. For concurrency testing, tools like Apache Bench (ab) or Siege can help determine if the FilesystemAdapter introduces a latency penalty that outweighs the RAM savings in your specific I/O environment.