contao / manager-bundle

[READ-ONLY] Contao Manager Bundle
GNU Lesser General Public License v3.0
17 stars 10 forks source link

cache warmup missing in Composer\ScriptHandler in 4.5 #59

Closed fritzmg closed 6 years ago

fritzmg commented 6 years ago

In version 4.5, the cache:warmup was removed from

Contao\ManagerBundle\Composer\ScriptHandler::initializeApplication

Is there any particular reason why? This leaves the website in an inefficient state after a composer operation, if you do not manually run

vendor/bin/contao-console cache:warmup
leofeyer commented 6 years ago

cache:clear also warms up the cache. They had deprecated it for a couple of weeks but later reverted the deprecation, so it is fine to use cache:clear only.

fritzmg commented 6 years ago

There still seems to be a difference. This is the state of var/cache/prod after cache:clear:

    annotations.map
    appProdProjectContainer.php
    appProdProjectContainer.php.meta
    appProdProjectContainerUrlGenerator.php
    appProdProjectContainerUrlGenerator.php.meta
    appProdProjectContainerUrlMatcher.php
    appProdProjectContainerUrlMatcher.php.meta
    Container2y5l8mc/
    contao/
    templates.php

And this is the state of the cache after cache:warmup:

    annotations.map
+   annotations.php
    appProdProjectContainer.php
    appProdProjectContainer.php.meta
    appProdProjectContainerUrlGenerator.php
    appProdProjectContainerUrlGenerator.php.meta
    appProdProjectContainerUrlMatcher.php
    appProdProjectContainerUrlMatcher.php.meta
+   bundles.map
    Container2y5l8mc/
    contao/
+   pools/
    templates.php
+   twig/

Furthermore, this is the average response time for the first request after cache:clear on my local environment:

And this after cache:warmup:

The latter provides an over 144ms better result.

leofeyer commented 6 years ago

That's interesting. Which commands exactly did you run? You should compare

to

fritzmg commented 6 years ago

I've tested the following way:

rm -rf var/cache/prod
vendor/bin/contao-console cache:clear

and

rm -rf var/cache/prod
vendor/bin/contao-console cache:warmup

I did this before each request to ensure consistency. I did it 5 times for each case and took the average response time.

Note: I have used rm -rf var/cache/prod to ensure that the cache is cleared properly (since at least under Windows errors can happen during cache:clear due to file or operating system shenanigans). cache:clear --no-warmup should be equal to rm -rf var/cache/prod.

leofeyer commented 6 years ago

What is the content of the contao/ folder in each case?

fritzmg commented 6 years ago

The content of var/cache/prod/contao is identical in each case.

Btw., when using cache:clear, the pools folder will be generated on the first request. However, it will have much less content than with cache:warmup.

The twig folder is generated with the first back end request (since the back end uses twig templates in Contao 4.5).

annotations.php and bundles.map will also be generated on the first request.

leofeyer commented 6 years ago

Hm, that does not make much sense, does it? Both cache:clear and cache:warmup will warm up the cache and they should not produce different results IMHO. Maybe a Symfony bug?

fritzmg commented 6 years ago

Can you reproduce it? May be it only occurs on Windows? I'll also try on a Linux machine.

fritzmg commented 6 years ago

I was actually unable to reproduce this on a Linux based shared hosting environment...

leofeyer commented 6 years ago

Yes I can reproduce it. But both cache:clear and cache:warmup execute the same warmers, so I really don't understand it.

string(67) "Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer"
string(66) "Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer"
string(60) "Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer"
string(65) "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer"
string(62) "Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer"
string(57) "Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer"
string(41) "Contao\CoreBundle\Cache\ContaoCacheWarmer"
leofeyer commented 6 years ago

Anyway, we should probably just re-add the cache:warmup.

fritzmg commented 6 years ago

And --no-warmup to be safe?

leofeyer commented 6 years ago

Yes. Basically the code from Contao 4.4.

https://github.com/contao/manager-bundle/blob/df75e0381fddd3f505e8adb982c5650c8502954c/src/Composer/ScriptHandler.php#L37-L38

leofeyer commented 6 years ago

Fixed in 77c85e2906896e55f9b76de41d0812ee6d55e7be.