-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Significant performance issue in database queries after upgrading Phalcon v3.4 to v5.4 #16474
Comments
Of course I figured out my problem right after opening this issue. First of all those options that Phalcon PDO sets by default do make a difference, but I used them in the wrong place while testing with And now with the option This option is set to Also this option is set to It was kind of weird upgrading the framework version and getting this kind of a performance drop without any warning in the upgrade notes. It would be good to either not set this to If the option should just not be set by default for MySQL, let me know and I will open a pull request. If possible I would like to contribute to Phalcon by more than just opening this issue. |
I suspect that turning off emulation mode is to align the behavior with PostgreSQL. |
I agree. |
Phalcon's model has a schema, so Phalcon should know what type it is, right? |
Related: #15361 |
@niden |
Resolved in #16486 Thank you @ZanMaticPratnemer and @s-ohnishi |
Describe the bug
I recently upgraded our application from PHP 7.3 and Phalcon v3.4 to PHP 8.2 and Phalcon v5.4, expecting a performance improvement, but the whole application was slower for approximately 40%. I made some changes to the code that were necessary for it to work on newer versions of the language and the framework, but no functional changes, only some optimizations. I made the optimizations only after noticing the problem described bellow.
After turning on the profiling tools I noticed that the main reason was the function `\PDO->prepare'. In PHP 8.2 and Phalcon v5.4 it took anywhere from 400x to 1000x more time to execute compared to the old version of the application (PHP 7.3 and Phalcon v3.4).
Since our application sometimes needs to make a lot of database queries for a single request, the performance issue of this function can add up to multiple seconds of additional loading time.
To Reproduce
I created a cli task that clearly shows the problem. This task contains two actions, one to prepare 10000 statements with
\PDO
and another to prepare the same amount of statements with\Phalcon\Db\Adapter\Pdo\Mysql
. I ran these tasks on 4 different environments: our staging server with PHP 7.3 and Phalcon v3.4, our staging server with PHP 8.2 and Phalcon v5.4, development docker environment with PHP 7.3 and Phalcon v3.4 and development docker environment with PHP 8.2 and Phalcon v5.4. Only the two cases of preparing statements with\Phalcon\Db\Adapter\Pdo\Mysql
on Phalcon v5.4 had performance issues.Output of these tasks on our staging server with PHP 8.2 and Phalcon v5.4:
The results were similar if I ran these tasks inside the docker container. With PHP 7.3 and Phalcon v3.4 both actions took approximately the same amount of time to execute (server and docker container).
Expected behavior
Both actions should take approximately the same amount of time to execute.
Details
Additional context
I took a quick look into Phalcon source code and saw that the way that I use the Phalcon PDO in the above tasks, the following options were also set (maybe I missed some):
After setting these options in
PreparepdoAction()
, performance didn't change.I also tried using the Phalcon PDO without the dialect and without named binds, again - nothing changed.
Even tried using the Phalcon PDO with a simpler query :
SELECT 'id' FROM 'page'
. It still took about 8.5 seconds to execute.Disabling XDebug only improved the performance by about 0.5 seconds.
Let me know if I should provide any other environment info, profiler outputs or anything else.
The text was updated successfully, but these errors were encountered: