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
Become very slow after update from 2.0.5 to 2.0.14 #15776
Comments
It is impossible to guess from your composer config what's the reason for slowing down :-) I would recommend first deleting all caches (assets, cache, browser delete history) and if the issue still occurs then run profiler to narrow the reason - e.g. is it database, HTTP requests, javascript of PHP or what is actually slowing down .. Profiler will show you which files / classes / methods consume most of response time .. |
Also please try 2.0.13. |
Thanks for posting in our issue tracker.
Thanks! This is an automated comment, triggered by adding the label |
@samdark |
We've just tagged 2.0.14.1 btw. with regression fixes. |
2.0.5 — 2.0.13 is still too broad. Maybe try git bisect to find out what change affected your project? http://en.rmcreative.ru/blog/finding-bug-with-binary-search/ |
the problems occured only in version 2.0.13 and above |
Still too broad. Please do git bisect to find out the culprit. Thanks. |
And this behavior is probably related to a frontend. It doesn't seem to be related to a backend part of Yii. |
also when i update to 2.0.14.1 from 2.0.13.1 my project become a little slower |
@hooman-pro we need some help to find a reason of a slowdown. Could you try git bisect to find out what change affected your project? http://en.rmcreative.ru/blog/finding-bug-with-binary-search/ |
It is for sql runing before update to 2.014 |
Please do git bisect. It's impossible to find out what's wrong otherwise. |
I can not understand ! It seems the frame work method for running sql changed |
Yes but between the two versions you've mentioned there are many commits and you have a code to test against via git bisect. We don't have it. |
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. EDIT: Is not the same. it is a new method |
It is strange. I have two different projects updated to 2.0.14.1, but only one of them executes this query. Also this query does not display an origin in debug panel. |
@Eseperio which DB server is that? MySQL? |
Yes. |
@rosancoderian, @hooman-pro do you use DbSession? @Eseperio that's because DBSession was switched to use atomic upserts to solve concurrency issues. Upsert requires extra schema data. In production it's cached so there should be no extra queries at all. |
Yes I use mysql too and store Session in Db |
Stack trace from loadTableConstraints when using DbSession
|
@samdark I did'nt see your edit. Ok. But it is a pain in the ass when developing locally. |
@Eseperio what reason stops you to use schema cache when developing locally? |
Yes. Migrations are great, great if you develop a project in a team or if a project is modular. I use them everyday for projects with my team. But when developing simple project i don´t create migrations of any change i make, i use DDL. And IMHO i think this is what many user do. |
Yii also provides a console command to flush cache (per cache/all registered caches). |
Added docs |
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 |
Wow, 2 seconds? O_o That's a really a lot of time. |
Is that MySQL, @MartijnHols? |
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. |
Using the data in the I tried booting a new docker container of MariaDB and creating multiple databases (5) with the 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. SELECT #DISTINCT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
# `tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = `sch`.`name` THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
# `rc`.`UPDATE_RULE` AS `on_update`,
# `rc`.`DELETE_RULE` AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM (SELECT DATABASE() AS `name`) AS `sch`
INNER JOIN `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`
ON `kcu`.`TABLE_SCHEMA` = COALESCE(NULL, `sch`.`name`) AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
#LEFT JOIN `information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`
# ON `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
#LEFT JOIN `information_schema`.`TABLE_CONSTRAINTS` AS `tc`
# ON `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
ORDER BY `kcu`.`ORDINAL_POSITION` ASC 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: SELECT #DISTINCT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
`tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = `sch`.`name` THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
# `rc`.`UPDATE_RULE` AS `on_update`,
# `rc`.`DELETE_RULE` AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM (SELECT DATABASE() AS `name`) AS `sch`
INNER JOIN `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`
ON `kcu`.`TABLE_SCHEMA` = COALESCE(NULL, `sch`.`name`) AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
#LEFT JOIN `information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`
# ON `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
LEFT JOIN `information_schema`.`TABLE_CONSTRAINTS` AS `tc`
ON `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
ORDER BY `kcu`.`ORDINAL_POSITION` ASC This takes 78ms: SELECT `tc`.`CONSTRAINT_TYPE` FROM `information_schema`.`TABLE_CONSTRAINTS` AS `tc` WHERE `tc`.`TABLE_SCHEMA` = 'my-database' AND `tc`.`CONSTRAINT_NAME` = 'PRIMARY' 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 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. |
Hi @MartijnHols . (SELECT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
`tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = :schema THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
`rc`.`UPDATE_RULE` AS `on_update`,
`rc`.`DELETE_RULE` AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM
`information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
`information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`,
`information_schema`.`TABLE_CONSTRAINTS` AS `tc`
WHERE
`kcu`.`TABLE_SCHEMA` = :schema AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
AND `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`CONSTRAINT_TYPE` = 'FOREIGN KEY'
)
UNION
(SELECT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
`tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = :schema THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
NULL AS `on_update`,
NULL AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM
`information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
`information_schema`.`TABLE_CONSTRAINTS` AS `tc`
WHERE
`kcu`.`TABLE_SCHEMA` = :schema AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`CONSTRAINT_TYPE` in ('PRIMARY KEY', 'UNIQUE')
)
ORDER BY `position` ASC
; |
I just checked my internal repo and realized that I put the first version of the query, not the optimized one. >_< |
@berosoboy Looks to be slower; 2750ms. While doing the process of removing databases and tables not used by the Yii app I noticed it got quicker as I removed things with a single jump from 600ms to 100ms after reaching a certain threshold. My guess was that this had something to do with the query cache. This is kinda strange because I had seen earlier that the amount of records this query accesses was just 1*61 rows, but the jump from 600ms to 100ms clearly indicated swapping to disk paging after a certain threshold. After some experimentation I found a possible solution in the MariaDB config. If I set Running an explain on the query shows this: This and the fact My old setting for
|
@MartijnHols thanks for the reply. Could you try again my proposed query, but now specifiying the |
(SELECT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
`tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = :schema THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
`rc`.`UPDATE_RULE` AS `on_update`,
`rc`.`DELETE_RULE` AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM
`information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
`information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`,
`information_schema`.`TABLE_CONSTRAINTS` AS `tc`
WHERE
`kcu`.`TABLE_SCHEMA` = :schema AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
AND `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`CONSTRAINT_TYPE` = 'FOREIGN KEY'
AND rc.TABLE_NAME = 'session' AND tc.TABLE_NAME = 'session'
)
UNION
(SELECT
`kcu`.`CONSTRAINT_NAME` AS `name`,
`kcu`.`COLUMN_NAME` AS `column_name`,
`tc`.`CONSTRAINT_TYPE` AS `type`,
CASE
WHEN NULL IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = :schema THEN NULL
ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
END AS `foreign_table_schema`,
`kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
`kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
NULL AS `on_update`,
NULL AS `on_delete`,
`kcu`.`ORDINAL_POSITION` as `position`
FROM
`information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
`information_schema`.`TABLE_CONSTRAINTS` AS `tc`
WHERE
`kcu`.`TABLE_SCHEMA` = :schema AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = 'session'
AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
AND `tc`.`CONSTRAINT_TYPE` in ('PRIMARY KEY', 'UNIQUE')
AND tc.TABLE_NAME = 'session'
)
ORDER BY `position` ASC
; is quick (~15ms) even without anything in the cache. |
Awesome! |
I had originally a query with 2 |
@sergeymakinen did not you mean berosoboy? ;) |
@berosoboy ca4e1a5. Sorry. |
Teamwork! |
Okay, cheers for everyone! :) |
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
The text was updated successfully, but these errors were encountered: