Skip to content
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

Perf & Timeout issue with PHP-FPM 8.1 #1564

Closed
EggIt opened this issue Jun 10, 2023 · 2 comments
Closed

Perf & Timeout issue with PHP-FPM 8.1 #1564

EggIt opened this issue Jun 10, 2023 · 2 comments
Labels

Comments

@EggIt
Copy link

EggIt commented Jun 10, 2023

Description:
Hello,

I have a laravel lambda function running on PHP 8.1 / bref 2.0 / php-81-fpm layer
which is facing timeouts when trying to access my API endpoints (timeout is set to 30 seconds).

Upon investigating logs, bref seems to have 2 distinct behaviors upon calling one of my API endpoints :

1st behavior

Requests are gracefully terminated and response is 200 OK
Nevertheless, the execution is taking around 3 seconds to reach my first line of code which is simply logging a BEGIN string

2023-06-09T23:31:18.917000+00:00 2023/06/09/[$LATEST] START RequestId: e87bb35d-75b9-4c59-baa1-e75d4bdfc059 Version: $LATEST
2023-06-09T23:31:22.654000+00:00 2023/06/09/[$LATEST] [2023-06-09 23:31:18] local.INFO: >>>>>> BEGIN 0

In this first case, bref is not logging anything but something seems to be taking too much time

2nd behavior

Requests are timed out by bref after the 29 seconds threshold.
Bref here consumes all the 29 seconds leaving nothing much for my API to respond, in the logs below we can see how much time bref is taking and interrupting the execution of my endpoint...

023-06-09T23:33:10.117000+00:00 2023/06/09/[$LATEST] START RequestId: 5f6abe22-ba3d-4486-b335-caa990c83bbe Version: $LATEST
2023-06-09T23:33:39.147000+00:00 2023/06/09/[$LATEST] The PHP script timed out. Bref will now restart PHP-FPM to start from a clean slate and flush the PHP logs.
2023-06-09T23:33:39.147000+00:00 2023/06/09/[$LATEST] Timeouts can happen for example when trying to connect to a remote API or database, if this happens continuously check for those.
2023-06-09T23:33:39.147000+00:00 2023/06/09/[$LATEST] If you are using a RDS database, read this: https://bref.sh/docs/environment/database.html#accessing-the-internet
2023-06-09T23:33:39.147000+00:00 2023/06/09/[$LATEST] [2023-06-09 23:33:10] local.INFO: >>>>>> BEGIN 0
2023-06-09T23:33:39.148000+00:00 2023/06/09/[$LATEST] [09-Jun-2023 23:33:39] NOTICE: Terminating ...
2023-06-09T23:33:39.149000+00:00 2023/06/09/[$LATEST] [09-Jun-2023 23:33:39] NOTICE: exiting, bye-bye!

It seems the following bref code is facing some problems but i am stuck as no stacktrace is provided..

        try {
            $socketId = $this->client->sendAsyncRequest($this->connection, $request);

            $response = $this->client->readResponse($socketId, $timeoutDelayInMs);
        } catch (TimedoutException) {
@EggIt EggIt added the bug label Jun 10, 2023
@EggIt EggIt changed the title Perf & Timeout issue with PHP-FPM Perf & Timeout issue with PHP-FPM 8.1 Jun 10, 2023
@mnapoli
Copy link
Member

mnapoli commented Jun 10, 2023

Thanks for the great report!

FYI to clarify for the second behavior: it's "normal" that the BEGIN 0 line appears after 29 seconds. This is because FPM only flushes logs after the timing is caught (#1133).

So for the 2nd behavior, there's no indication that it's something in Bref taking 29s, it could be the application code.

That being said, the 1st behavior is interesting because clearly BEGIN is written after 3 seconds, which is not normal. The START line is written after Bref is fully initialized, so it could be something in Laravel (when booting the app) that takes a long time?

Are you running inside a VPC? If yes, it could be related to this: https://bref.sh/docs/environment/database.html#accessing-the-internet

@mnapoli
Copy link
Member

mnapoli commented Mar 19, 2024

Closing because of inactivity.

@mnapoli mnapoli closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants