yii2: Become very slow after update from 2.0.5 to 2.0.14
my app become very slow after update from 2.0.5 to 2.0.14. it become normal after i downgrade it back to 2.0.5.
PHP version 7.1 Ubuntu 16.04 composer.json
{
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.14",
"yiisoft/yii2-bootstrap": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0",
"moonlandsoft/yii2-phpexcel": "*",
"mdmsoft/yii2-admin": "~2.0",
"yiisoft/yii2-jui": "~2.0.0",
"dompdf/dompdf": "^0.8.2"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
"yiisoft/yii2-gii": "~2.0.0",
"yiisoft/yii2-faker": "~2.0.0",
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1",
"codeception/specify": "~0.4.3"
},
"config": {
"process-timeout": 1800
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
],
"generateCookieValidationKey": [
"config/web.php"
]
},
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 46 (43 by maintainers)
Commits related to this issue
- Fixes #15776: Fixed slow MySQL constraints retrieving — committed to yiisoft/yii2 by sergeymakinen 6 years ago
- #15776: Removed unnecessary UPGRADE note, added @berosoboy to changelog [skip ci] — committed to yiisoft/yii2 by samdark 6 years ago
I just checked my internal repo and realized that I put the first version of the query, not the optimized one. >_< I’ll make a PR tonight.
Db Schema query, in my case, has became a lot slower after upgrading from 2.0.13.1 to 2.0.14.1. Up to 1 second. If schema cache is not enabled this can be the cause of slower websites.
Using MySQL 2.0.13.1 - 0.4ms
2.0.14.1 - 888ms
EDIT: Is not the same. it is a new method
loadTableConstraintsadded in #14105Using the data in the
information_schemadatabase from my home pc that I exported it’s as quick on my work computer. Because of this I guess it might be an issue with the contents of theinformation_schemadatabase, my experience with joins is that they get slow when there’s a lot of data being joined which led me to think it’s either the amount of databases I have running (only 20 including the MySQL databases), or the fact I have multiple databases withsessiontables (about 5 of them I think).I tried booting a new docker container of MariaDB and creating multiple databases (5) with the
sessiontable, but that didn’t result in any noticeable slowdown. I tried exporting my work pc’sinformation_schemaand re-importing it in a different database (with tables made non-temporary because it wouldn’t otherwise appear) and running the query on that is really quick.I tried to find what part of the query is slow, and learned that each left-join is responsible for about half the execution time (900ms). Without the left joins it’s near instant. I tried changing the on-conditions so the records resulting from the left-joins is just for the current table (currently it fetches the constraints from all tables, not sure if intended), without any change. Running queries directly on the respective tables is near instant, just the joining seems to be slow even though this:
takes ~16ms and results in only 1 record, so it’s not like the left-joining should be any different from a single query directly on the table.
This takes 969ms:
This takes 78ms:
I’m not sure how to continue debugging but in any case this looks to be an issue with MariaDB. It might be fixable by changing the query further but I’m not sure how to proceed with that as I’m not sure about everything it’s used for. e.g. I can imagine the
TABLE_CONSTRAINTSquery could be a subquery instead which might be quick but that would result in only one record being returned (in the case of thesessiontable that would be right, but the same query is likely also used for other tables).I updated MariaDB to 10.2.13 without any changes.
Next I’ll try to reproduce this in a Docker container and perhaps rebuild my database to see if it’s maybe somehow corrupt. I’d be surprised if the issue remains afterwards, but if it does I’ll start removing databases until the issues is fixed or just one Yii2-app-database remains. If it persists I’ll strip that down to the bare minimum to reproduce the issue.
@sergeymakinen did not you mean berosoboy? 😉
MariaDB just like @Eseperio. On my work desktop it was about 1900ms (first call after restarting the service was 2500ms). I ran the query via HeidiSQL as well to see the results without hacking into the code and it took as much time, even after restarting the service. Using caching restored the response times so it didn’t seem like a big deal to me,
Just now I tried reproducing it at my home pc and the same query only takes about 100ms, so there might be something else going on at my work computer. I’ll try to find out if there’s a difference in versions or settings or if I can explain it some other way tomorrow.
I suggest also mentioning it (in an obvious way) in any docs suggesting using DbSession, such as here: http://www.yiiframework.com/doc-2.0/yii-web-dbsession.html Otherwise new users of this session data storage will run into this same issue. Also it was one of the first search results I ran into when I started debugging this issue. The new query adds about 2 seconds to every single request for me.
Yes I use mysql too and store Session in Db