-
-
Notifications
You must be signed in to change notification settings - Fork 15
Handle requests with the Kernel + handle events with Symfony services - Symfony Runtime integration #45
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
Conversation
| } | ||
| }, | ||
| "files": [ | ||
| "src/bootstrap.php" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file registers the Symfony container in Bref. It will be called for every invocation/request.
|
Performance improvements may actually be better than just shaving the 1ms of booting the Symfony Kernel: https://blog.laravel.com/vapor-octane-support-is-now-available |
|
First, thanks to everyone involved in moving this forward 💚 If I understand correctly, this is NOT using the Symfony Runtime and https://github.com/php-runtime/bref would become useless. Also, I suppose the referenced services like The approach seems very pragmatic given what Bref already allows to do with PSR-7/15 and PSR-11. I think it makes a ton of sense and the benefit could be huge (see below). Looking at Vapor + Octane, they have an interesting feature which is limiting the time the DB connection is kept open. Didn't looked at how they did it but it could be interesting to do the same to avoid keeping DB connections stale for too long and running out of connections. For example, I have a project that runs a scheduled Lambda once a week but this lambda sends dozens of SQS messages each of those triggering a Lambda doing the same (I was sweaty when working on this 😰). In a couple of minutes, I invoke hundreds of different Lambda containers, if thay all kept a connection open i could rapidly run out of connections. I've tried this on a project of mine using the following
Running a bunch of benchmarks I noticed an average warm response time of 500ms with the current stack and 300ms when using this PR 🎉 The same gap was noticed in the Cloudwatch Lambda execution times. Cold starts didn't seemed to be impacted by this change. This is very empiric and on a small dataset but the benefit seem large enough to be worth it. Let me know if i can help 🙂 |
|
Thank you for this PR. I also appriciate the work to move this forward. I like the implementation and I think it makes sense. This is a Symfony specific approach and I see that there are a lot more steps compared to an alternative. PHP-FPM: This PR (web2 (App/Kernel): Alternative: As @t-richard points out. There is no use of the runtime component. So any special logic you have in your index.php will only run locally, and not on Lambda. |
src/HandlerResolver.php
Outdated
| /** | ||
| * Create and return the Symfony container. | ||
| */ | ||
| private function symfonyContainer(): ContainerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want to get a container but not from a Symfony Kernel?
Or is this exclusively a Symfony solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in this case you would use the default Bref PSR-11 support and not bother with this bridge ?
https://github.com/brefphp/bref/blob/master/src/Bref.php#L27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is 100% about Symfony (since this is in the symfony bridge project)
Look in `public/index.php` by default.
# Conflicts: # .github/workflows/ci.yml # composer.json
|
Last steps: resolve the |
|
I am going to merge and release a beta version. Let's see if everything works out fine! I'm happy to say I think we finally have a solution that implements and supports Symfony Runtime, and still provides a great user experience with the direction integration with the container! |
|
Could you help me to understand how I could use Symfony runtime with Docker image? I build my Docker image like this: But Lamda fails with error |
|
Please open a separate issue (or rather a GitHub discussion since this is more about support than a bug. In your case I think you would need to set |
Following discussions and iterations with @Nyholm, he identified the following ways to improve the DX for Symfony users:
This PR exposes a possible solution. It integrates with Bref's PSR-11 support for resolving handlers: handlers are resolved from the Symfony container.
Principle
The
bref/symfony-bridgepackage automatically registers the Symfony Kernel: it will be used by Bref to resolve Lambda handlers.Example:
How it works
With this PR, Bref delegates resolving the handler to the Symfony container.
File names still work (e.g.
public/index.php): these will still be resolved by Bref as usual.Class names are resolved by Symfony's container (e.g.
App\KernelorApp\Service\MySqsService).There is one particular case:
App\Kernel(the Symfony kernel) is integrated with Bref (PSR-15 integration in Bref) to handle API Gateway's HTTP events.Performances
I deployed a new Symfony 5.3 application with a single "Hello world" route. It runs in
APP_ENV=prodin Lambda, but deployed without cache (I wasn't benchmarking the cold starts so I left it up to Symfony to create the cache on the first invocation in Lambda).I measured the Lambda "Duration" for 500 hot invocations:
Again, cold starts are intentionally omitted because AFAIK they aren't impacted here.
Conclusion: web apps could save ~1ms over their response time. They may be able to save more the Kernel boot is long, or by keeping some connections (e.g. db connections) alive.