# Cakephp 3 slowdown

**URL:** <https://discourse.cakephp.org/t/cakephp-3-slowdown/8248>\
**Category:** Performance\
**Created:** [August 19, 2020, 6:18pm UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248 "2020-08-19T18:18:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsaboutcode](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/itsaboutcode/32/1969_2.png) [@itsaboutcode](https://discourse.cakephp.org/u/itsaboutcode)\
**Post date:** [August 19, 2020, 6:18pm UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/1 "2020-08-19T18:18:21Z")

</div>

Hi,

We are facing a strange problem. We have mysql 5.7 and have `innodb_stats_on_metadata` set as false by default but as a precaution we have also have disabled it with following command.

`set global innodb_stats_on_metadata=0;`

But each request is adding 3 seconds in comparison to if we shift same code to cake2. Cake3 queries generate following slow queries on information\_schema.

```
    SELECT * FROM information_schema.key_column_usage AS kcu
INNER JOIN information_schema.referential_constraints AS rc
ON (
    kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
    AND kcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
   )
WHERE kcu.TABLE_SCHEMA = 'stagingdb' AND kcu.TABLE_NAME = 'api_tokens' AND rc.TABLE_NAME = 'api_tokens'
```

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [August 19, 2020, 7:15pm UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/2 "2020-08-19T19:15:08Z")

</div>

Is there a problem writing to the cache directory in your Cake3? I would expect any schema reflection tasks to be done once and cached.

It looks like this might be making the data that is stored in `tmp/cache/models`. But possibly I’m misunderstanding the role and source of this query.

---

<div class="post-metadata">

**Author:** ![itsaboutcode](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/itsaboutcode/32/1969_2.png) [@itsaboutcode](https://discourse.cakephp.org/u/itsaboutcode)\
**Post date:** [August 19, 2020, 7:30pm UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/3 "2020-08-19T19:30:42Z")

</div>

@dreamingmind - I checked the difference between our dev and staging/live env, `tmp/cache/models` directory did had 777 permission and I gave it to that directory but nothing is being created there.

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [August 19, 2020, 7:45pm UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/4 "2020-08-19T19:45:26Z")

</div>

Resolving that is above my pay grade. But if there are no cache files in there, it sounds like a candidate for the source of your problem. It should be chock-full of table schema data; stuff that makes the ORM/Entity/Form magic happen.

---

<div class="post-metadata">

**Author:** ![anon81960487](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@anon81960487](https://discourse.cakephp.org/u/anon81960487)\
**Post date:** [August 26, 2020, 4:29am UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/5 "2020-08-26T04:29:59Z")

</div>

I would suggest updating your database just to eliminate that as a potential issue. Older versions of MySQL are a bit unstable in my experience.

---

<div class="post-metadata">

**Author:** ![itsaboutcode](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/itsaboutcode/32/1969_2.png) [@itsaboutcode](https://discourse.cakephp.org/u/itsaboutcode)\
**Post date:** [August 26, 2020, 5:52am UTC](https://discourse.cakephp.org/t/cakephp-3-slowdown/8248/6 "2020-08-26T05:52:41Z")

</div>

We were able to get it fixed by restarting the db but we were still not sure what was happening.

Finally we figured that there was a query in our db which was generating an error and creating a small file on disk (thousands and thousands of such files were there), which was slowing down cakephp 3 (cakephp 2 was working fine). Shutting down that query and cleaning the space also worked.

Still don’t know how it was effecting cake3 but not cake2.
