0

I'm having troubles with my site being super slow. It seems like caching isn't working. When I upload the site to a different server, everything seems fine. When I empty the template cache and load the page, there are ~9000DB queries which take about 7s. On the page where the caching works, on the next page load only 55DB queries are necessary which take 2,6s.

The only differences I'm aware of now regarding the servers is, that the "slow" one is running with MySQL 5.5 and NGINX while the other uses 5.7 and Apache.

What needs to be installed or configured on the server for caching to work? I do use {% cache %} tags in the twig-code.

5
  • I think 9000 database connections is a big number, I never observed that much with any of my sites (using crafts debug toolbar). If this number is related to a very big and complicated site, then you probably cant just use the cache tag to ameliorate the page load time. On the server where you think the caching does not work, do you see new files being generate in storage/runtime/cache and storage/runtime/compiled_templates ? This article is a little older but has been updated by Andrew lately: nystudio107.com/blog/the-craft-cache-tag-in-depth – MisterMike Feb 8 at 8:29
  • I deleted the two folders (cache and compiled_templates) and yes, new files are generated. So it means that caching works, right? What else could be the reason for making this huge amount of DB queries over and over again? The "craft_templatecaches" table, as mentioned in the article is empty on both servers. I know it's a lot of queries and when doing research I came across Eager Loading. I will try to implement it, but I don't think this will be the final solution, since even the status quo can run fast, as the second server shows. – obs Feb 8 at 15:56
  • Check if any page of the website has 9000 db queries, meaning you'll have to narrow the queries down. Maybe you're doing something repeatedly where you are unaware on its implications to the db. But without knowledge of the code, its hard to tell. The final solution is something where you "fix" the queries and where caching is working. Something invalidates the template caches, so while the files are being generated, they get replaced with new ones on every request. That said I could imagine these two issues stick together.. – MisterMike Feb 9 at 9:42
  • But when the cache get invalidated, why would it work on one server and not on another? I thought there is some issue with the server configuration, don't you think? – obs Feb 9 at 9:53
  • I cant tell you from here what is being served to the browser in terms of the cache. Check both site conf files. Check both .env files, check for devMode. You certainly should start profiling your site. What does the debug toolbar tell you about the most time consuming db query? You can sort by execution time ("duration") to find the slow queries. – MisterMike Feb 9 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.