In a typical Symfony project there are multiple caches built when running the cache:warmup
command. By pre-building those caches and putting them into the container, the startup time can be reduced.
/var/www/app/var/cache/[env]/doctrine/orm/Proxies
✅ Already in container/var/www/app/var/cache/[env]/translations/catalogue.gl.whsXFTx.php
/var/www/app/var/cache/[env]/annotations.php
/var/www/app/var/cache/[env]/url_generating_routes.php
%env(parameter_name)%
to not leak any parametersHow to test:
CACHE_WARMUP=0
and run a request or bin/console
. Run docker diff [image-hash]
to list the changed files since the start. var/cache/[env]/ContainerXYZ
and way less files compared to running the image with CACHE_WARMUP=1
Measurements of a web-server pod using PHP-FPM and a separate nginx container:
Times before optimizations
Best time: 1 + 70s = 71 s
Worst time: 60 + 44 + 1 + 15 + 70 = 190 = 3m 10s
Reducing the initial readiness probe delay (best case):
1 + 25s = 26s reduction of 63,4% vs current best case
Pre-building cache (best case):
1 + 1s = 2s reduction of 97,1% vs current best case
Pre-building cache (worst case):
1m 44s + 15 + 1 + 1 = 2m 1s ~33% faster than current worst case
⚠️ Something is wrong with preload, unclear what.
Without preload:
hyperfine -r 1000 --warmup 10 "bash test.sh" Time (mean ± σ): 68.9 ms ± 12.6 ms [User: 3.7 ms, System: 5.9 ms] Range (min … max): 42.3 ms … 179.9 ms 1000 runs
With preload:
hyperfine -r 1000 --warmup 10 "bash test.sh" Time (mean ± σ): 67.2 ms ± 32.9 ms [User: 3.5 ms, System: 5.5 ms] Range (min … max): 57.5 ms … 1074.3 ms 1000 runs