-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Exception thrown unless Symfony cache directory is also changed to /tmp/...
#39
Comments
/tmp/...
/tmp/...
Regarding the memory size problem, you could try increasing the memory limit of PHP by customizing the
Agreed, this is not really efficient in production that's why it's better to pre-generate the cache.
This is surprising, but since I wrote (and tested) bref-symfony-demo we have added some extensions to PHP (mainly opcache, the other extensions are disabled by default), maybe that could be it? I don't really know much more right now I'll try to dig in. |
The first thing I tried was to increase the I think the cache is not being pre-warmed during the deploy process, because presumably it should exist and be readable if it has been!? As mentioned, if you set the cache dir to the writeable |
OK, I'll try to reproduce that tonight and see how it goes. Thanks for opening the issue! |
We use our own kernel here, but since we also use The only way we found to do so is to use relative paths. For instance, we have a parameter Our kernel always check that the current working directory is This works and we don't build the container on each execution. I think you could do something similar with the Symfony kernel. That beeing said, if you have a better solution, I would be very interested. |
@nealio82 I've updated ( @t-geindre Yes! I had issues with absolute/relative paths when deploying the API platform demo for my benchmarks. In the end I gave up and stored the cache in |
I probably won’t have time tonight, but i’ll create a version which breaks
/ screengrab reproduction steps
…On Mon, 9 Jul 2018 at 18:49, Matthieu Napoli ***@***.***> wrote:
@nealio82 <https://github.com/nealio82> I've updated (composer update)
everything to the latest versions on the symfony-demo project and
redeployed, it still works:
https://7oaryq3rzl.execute-api.eu-west-3.amazonaws.com/dev I don't
understand what breaks for you 🤔
@t-geindre <https://github.com/t-geindre> Yes! I had issues with
absolute/relative paths when deploying the API platform demo for my
benchmarks. In the end I gave up and stored the cache in /tmp because I
was not measuring the cold starts, so I just had to warmup the application
and that's it. But this is not ideal at all.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABCVBs2lAnH5tdsVqgYsKKU_LW_aU-swks5uE5eOgaJpZM4VHpC8>
.
|
Interestingly, if I clone the The I made a screencast here: https://youtu.be/Ar3USl8h8Ug |
Thanks for the screencast! Could you try one last time |
I reverted my changes in
I see the same exception(s) related to the cache again
|
If I add the
see https://twig.symfony.com/doc/2.x/api.html#environment-options and http://symfony.com/doc/current/reference/configuration/twig.html#cache However, I don't like setting I also don't get why Twig needs to write to the cache if the templates are pre-compiled!? |
OK I think I remember now where the problem came from (when I tried deploying the API platform demo). Some things in the Symfony cache are using absolute paths, as @t-geindre mentioned. You need to tweak Symfony and its config to force it to use relative paths (because the paths on your machine and on AWS lambda are different). That works, except for Twig that IIRC uses Also it is important to note that not all the Symfony cache is pregenerated, for example you have to put Doctrine's cache (which is not pregenerated) in Here is an example of what I did for Doctrine in parameters:
writable_cache_dir: '/tmp/cache'
[…]
doctrine:
orm:
[…]
metadata_cache_driver:
cache_provider: metadata_cache
result_cache_driver:
cache_provider: result_cache
query_cache_driver:
cache_provider: query_cache
[…]
doctrine_cache:
providers:
metadata_cache:
aliases: [doctrine.orm.default_metadata_cache]
file_system:
directory: "%writable_cache_dir%/doctrine/metadata"
result_cache:
aliases: [doctrine.orm.default_result_cache]
file_system:
directory: "%writable_cache_dir%/doctrine/result"
query_cache:
aliases: [doctrine.orm.default_query_cache]
file_system:
directory: "%writable_cache_dir%/doctrine/query" I did the same for the user cache: framework:
cache:
directory: "%writable_cache_dir%/app" |
Ok, so I assume that means at some point we have to have a writeable filesystem in order for Twig to work properly? However, that raises 2 questions:
|
That could be a temporary solution. I still hope to find the correct configuration to apply to solve that (or maybe fix the problem in Twig/Symfony). But yeah it's better to have helpful documentation for now.
Yes I don't know how to explain that either :/ |
Ok, I can make a PR for this tomorrow :)
…On Fri, 13 Jul 2018 at 20:25, Matthieu Napoli ***@***.***> wrote:
Should the Kernel.php in the documentation be updated to change the cache
dir to /tmp to make sure Twig can always write to it?
That could be a temporary solution. I still hope to find the correct
configuration to apply to solve that (or maybe fix the problem in
Twig/Symfony). But yeah it's better to have helpful documentation for now.
Why does your example work for you and not for me? You saw in the
screencast that I made no adjustments to the example repo's code!
Yes I don't know how to explain that either :/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABCVBtB0FkhbTNKAuTqR0t1-Rb5GHQVEks5uGPQVgaJpZM4VHpC8>
.
|
Workaround documentation added in #42 |
Does anyone here has a public repository to reproduce this? |
I can make one early next week (probably Monday)
…On Fri, 24 Aug 2018 at 14:07, Matthieu Napoli ***@***.***> wrote:
Does anyone here has a public repository to reproduce this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABCVBovYn0MTlVJHvnXypDufuXWx6MmXks5uT_qPgaJpZM4VHpC8>
.
|
For those reading this issue, I reproduced it when writing a simple Symfony 4 application, starting with Flex. I just have a base template (the layout) and a few pages that extend from that. I don't have time right now to create a whole repository to reproduce that but that can maybe be a starting point for others. |
Weirdly I tried yesterday; starting with Symfony 4 & extending a base template, then passing in some variables to render. I didn’t see the issue at all. (And i’m pretty sure the first time I saw the issue I didn’t even need to extend a base template) |
Hi! # config/packages/prod/twig.yaml
twig:
cache: '/tmp/cache/twig' I know it's a temporary solution but I preferer doing this because making |
Thanks that's a much better solution! I'll try to update the documentation in the coming weeks (I should have more time than this month), if anyone wants to get on this though feel free. |
@thibaudlemaire by any chance do you know why it adds a 4x overhead? Have you looked into that with Blackfire, for example? The Symfony best practice is to override it in the |
When you override the cache directory, pre-warmed cache cannot be used because either it's warmed up in your local The 4x overhead is due to the cache warmup when a Lambda container is created. I don't know exactly what is compiled at the first execution but I suppose : Doctrine proxies, annotations, Twig views, Kernel config, services container, etc. That's why we need to make Symfony use the pre-warmed cache. To do so, I thought about two solutions :
I use the second one because it's easier. But it's not ideal because twig views still need to be compiled on first invoke. |
Ah, of course! 🤦♂ |
Makefile cpu-specific
I'll be closing this issue since it was opened in 2019, and since then we have the Symfony bridge that should take care of the cache 🎉 |
Following the example code for Symfony and deploying, the request fails with the response
{"message": "Internal server error"}
.Checking CloudWatch logs shows 2 relevant entries:
and
Altering
Kernel.php
to include the following makes the problem go awayHowever...
Presumably setting the cache dir to Lambda's local
/tmp
kind-of defeats the point pre-warming the cache with the hooks in the.bref.yml
file? The object is to avoid launching the application without the cache already in place, right?.bref.yml
:serverless.yml
:bref.php
:I get the same behaviour with cloning the
mnapoli/bref-symfony-demo
repo and runningbref deploy
, and also with adding bref to asymfony/website-skeleton
project.The text was updated successfully, but these errors were encountered: