dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.54k stars 752 forks source link

Significant slowdown in Docker template after switching to FrankenPHP #669

Closed numerogeek closed 2 days ago

numerogeek commented 2 days ago

Hello,

Since switching to frankenPHP, I’ve noticed a significant performance drop in the Docker template. Specifically, I have a Symfony installation running on PHP, and the page load time has jumped to 40 seconds. This seems highly unusual as the Symfony profiler shows an execution time of only 175 milliseconds.

However, when I check Chrome’s Network tab, it consistently reports 40 seconds for every page refresh. I’ve already uncommented the necessary line - /app/vendor in compose.override.yaml, but this doesn’t seem to resolve the issue.

For reference, I’m running this setup on a MacBook Pro M2. Any insights or suggestions on what might be causing this slowdown would be greatly appreciated.

Thanks in advance for your help!

dunglas commented 2 days ago

Does this affect the default template, or a more advanced app?

If it's the later, would you be able to provide us a reproducer?

dunglas commented 2 days ago

This looks a bit like https://github.com/dunglas/frankenphp/issues/1010

It's a random guess, but could you try if it's as slow when using curl, and when disabling compression entirely?

numerogeek commented 2 days ago

Hello @dunglas,

Thanks for your suggestion. Here’s a short video showing how it behaves: https://www.youtube.com/watch?v=_lH1QE_HCuo. It's a fresh symfony install used for a SymfonyCast tutorial, nothing big here.

On the browser side, the load times are long, but when I test with curl, the performance is better, although still quite slow. I’ll look into disabling compression, which I believe is in the Caddyfile, right ?

Thanks in advance !

numerogeek commented 2 days ago

I tried removing this line encode zstd br gzip in the Dockerfile, then rebuilt and restarted the container, but I’m getting more or less the same results.

dunglas commented 2 days ago

I don't know if it's related but the SERVER_NAME value looks weird.

Are you using a Mac?

You can disable encoding in the Caddyfile, indeed (the encoding) line.

dunglas commented 2 days ago

Also, I'm curious to see the code of this "picture" endpoint.

numerogeek commented 2 days ago

Yes, I'm using a Macbook Pro M2. Why does it look weird to you ? It's a super basic project following the upload tutorial on sfcast: it's just a make:crud with a file upload : I just pushed the code here if you want to have a look: https://github.com/numerogeek/linkedinPP

numerogeek commented 2 days ago

Okay, you pointed me in the right direction. I changed the server name to server-name.localhost and it’s instant now. I was using server-name.local and modifying the hosts file to redirect server-name.local to 127.0.0.1, which seems to have been causing the issue.

I used your template and did a new fresh install without adding any code, and indeed, with the server name set to .local it’s very slow, but with .localhost everything works fine. I can’t explain why, but at least it’s working now.

Thanks for pointing me in the right direction!

maxhelias commented 2 days ago

Maybe an explanation : your .local is likely triggering mDNS resolution, which causes the slowdown, even with the hosts file configured. On the other hand, .localhost bypasses mDNS and directly points to 127.0.0.1, making it faster.

numerogeek commented 2 days ago

@maxhelias Thank you for the explanation. Good to know. Although I’m surprised that the MDNS Resolution takes so long.