-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[11.x] Improve MySQL connect init time by setting all our variables in a single shot #50044
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
[11.x] Improve MySQL connect init time by setting all our variables in a single shot #50044
Conversation
bb926b9
to
629ecec
Compare
Seems like a breaking change since my https://github.com/cgauge/laravel-aurora-connector/blob/main/src/AuroraConnector.php#L48 |
Yehhhh, it is technically a breaking change, but we do these kinds of breaking changes all the time in classes that people could be extending, such as adding new methods, which could in theory break code that extends and defines using the same name. That said, Laravel 11 is close around the corner, and if we have to re-target to that, it's not the end of the world. |
629ecec
to
1c74086
Compare
Just rebased this, without making any changes. Deploying into a real application... and consulting the general log to confirm this is doing what I expect. EDIT: indeed, this is working and doing what was expected. before:
after:
We can see the huge speed increase there too, comparing time between first and last statement execution times between the two (9.3ms -> 4.1ms), and under high DB load due to a spike of connections, the difference will be even greater. |
Very promising |
Sure, all code contributed here is under the terms of the MIT license, so as long as it's under the same license or a compatible license, there is no problem. |
The PostgresConnector has very similar functionality. It'd be great if someone could make the same improvement there. |
Hi @GrahamCampbell , take a look at this old PR, it might give you some other interesting insights. |
PG doesn't have syntax to set multiple configuration parameters in one statement. And its also not needed. You can set these parameters directly for a database user ( |
@GrahamCampbell would you mind sending this to master? Also note the |
Re-targetting at 11.x and updating to include the MariaDB driver. I won't do anything outside of MySQL and MairaDB within this PR. |
93d95ed
to
9943279
Compare
c23780b
to
80d1f9a
Compare
The current code does multiple round-trips to set all the variables we need for our config, both because there are multiple commands to run, but also because it's using prepare, for many of them - each use of prepare and execute causes 3 round trips - one to prepare, one to execute, and one to close statement (on garbage collection of the statement in PHP land). The MySQL SET command supports setting multiple things in a comma separated fashion. Refactoring to do this enables us to just run one SET statement against the server. This can make a real difference in a cloud situation such as AWS Lambda talking to an RDS database where we have to go cross-AZ with low single digit ms latency, instead of sub-ms latency. This also reduces load on the DB (fewer statements to execute), so spinning up a bunch of Lambdas in a burst will be less of a burden.
In principal this optimization could be applied to other drivers, too, but I've not included any of that in this PR.