People pages have a high amount of queries
complete
Amrayu78
The server has been having a high load and struggles to load certain pages, especially people pages.
I've made some updates to the view for people pages so it only shows 10 titles max with pagination.
As a result, the numbers of total titles, total movies, total dramas, total specials are incorrect now.
Please help to fix the load? I've added OPcache and updated configs for php. If you have any other ideas, let me know.
Amrayu78
complete
Amrayu78
Max Romanchenko: Another one, but this is an enhancement.
Max Romanchenko
Amrayu78 Yeah, I can see the problem. I am very sorry to hear that you are experiencing such problems. I don't know what happened, but the site is slowing down more.... Even in the admin panel I often get 500** errors that say that the server is overloaded. Also while working I am often redirected to Cloudflare - am I human? Maybe it has something to do with-- I don't understand why VDS can slow down so much.
The people page is not the highest loaded page, it only has two Views on it. During testing, I noticed that the slowdown is most caused by accessing intermediate post fields, ( slow queries from Toolset) and the relationship between person and Drama/Movie/Special.
I've adapted as much as possible a view that displays all related posts to the current person, that's all I can do unfortunately. After these optimisations I have seen a slight improvement in the loading of people pages. We can't change the pagination settings as we need to display the All tab items, it wouldn't make much sense. I am a bit disappointed in the speed of Toolset and in my future projects I will avoid using it unfortunately ((
Amrayu78
Max Romanchenko: Thanks for explaining Max. I'm not sure what else I can do to make things faster. Cloudflare is supposed to make the site faster because we have a lot of bots attacking. I have to leave it on for now so we don't get bombarded by bot scripts.
For people pages, I noticed the load gets better if I do not fully display everything for the all tab and if I used pagination it works okay. Should I go to Toolset's forum and ask them about this issue? Maybe they have some better way?
I've been monitoring the server's load whenever it slows down drastically and most times I see multiple "people" pages being hit which makes the site slow down a lot. Through trial and error and after fixing the people's view for all, it got a lot better.
Max Romanchenko
Amrayu78 Thank you for the information, Duong. Yes, I think you can post the problem on the Toolset forum, maybe the support will advise something.
Although I think they will advise something like this:
- Use a caching plugin (I don't think this is a good idea, as your authorised users will see outdated cached content).
- Use pagination (this is not an option, as we will have to remove the All tab and counter of post types (Drama, Movie and so on).
- You use many relationships and many post types, try to simplify it (this is also not an option, as the site structure cannot be redesigned at this stage).
However, I don't think these tips will help you much, but it's definitely worth a try.
I'm really sorry I can't be too helpful with this....
Amrayu78
Max Romanchenko: Thanks Max.
I have some questions to your comments.
- Cloudflare has caching built-in, I think it's possible to cache the people pages at the very least? I don't think it's a major deal to cache, maybe renew cache once a week or something?
- Understood.
- What would your recommendation be to simplify it? I'm failing to understand the many to many relationship. Would it be better to have it one to many? If the queries are slow for many to many, why would toolset even offer it then?
Max Romanchenko
Amrayu78 Hi Duong,
- Yes, I think you can try caching the pages and see how it goes with the cache, it should be much faster.
- My recomendations... Oops, to be honest in the current implementation with deep integration of relationshipfrom Toolset it is impossible to change the structure without losing data.
The ideal would be to simplify things so much that you don't use relationships at all. But that doesn't sound realistic, as everything has to be done from scratch.....
Relationships (many to many) are quite difficult to implement in Wordpress. A person can be in different films and different films relate to different people. It's a classic many-to-many relationship. The difficulty is that the relationship also keeps the fields, what exactly was the role of the person in this film.....
So the question is where to store the person's role in the Drama? In the Drama? Not quite right? In the People post? Not either. So Toolset uses an intermediate table (that's ok) in the database to store this data. Apparently therein lies the problem somewhere.
Difficulty 1. Storing relationship fields, it causes a slowdown.
Difficulty 2. Many types of posts in a relationship with a person (drama, movie, special). It would be much easier if it was a single post type, like "Title" and drama, movie, special would be its categories. But it's impossible because everything needs to be redesigned....
The simplest thing would be caching. Other options are quite difficult or impossible without redesigning the structure of the site.
Toolset provides a quick start so that everyone can do what they want without a deep understanding of what's going on under the hood. That's ok. but when time passes and the data starts to grow, problems appear....
Sorry for a lot of text and not much of a solution. Yes, I can try to defeat the Toolset and use a custom solution to store this relationship data. But that won't be compatible with the forms for adding / editing people to tittles.
So this problem is open.
Amrayu78
Max Romanchenko: Thanks for your detailed explanation. I think I understand the issue. Any ideas on how we should cache the people pages then?
I have CloudFlare cache and also OPCache on the database level turned on. If you know of a way to enable this for people pages specifically, please let me know.
Thanks.
Max Romanchenko
Amrayu78 As far as I know cache can't be enabled only for certain pages. It works the other way round. By default caching works for all pages of the site, but you can exclude some pages from the cache.
OPCache is a good option, this type of caching speeds up php processing, leave it enabled, but it's not enough. You need a full-page cache. Try playing around with the caching rules from CloudFlare.
The second option is an object cache (like Redis). This will require additional software to be installed on your server. This is a more complex way, since all requests are cached in RAM when the page is first generated, and then served to the user from RAM and not from the database. I think a full-page cache is easier to start with.
However, do not forget that full-page caching has a big disadvantage - it is outdated content. Users will not always see the latest changes and changes they just made. This may add some confusion...
Amrayu78
Max Romanchenko: Hi Max, There's a way to cache URI path in CloudFlare.
I've set the following rule in CloudFlare for now:
People Cache rule:
When incoming requests match...
- URI path contains /person
Then...
- Cache eligibility = Eligible cache
Edge TTL
- Ignore cache-control header and use this TTL:
- 7 days
Browser TTL
- override origin and use this TTL
- 7 days
Max Romanchenko
Amrayu78 Hi Duong, You're doing a great job!
I checked and caching seems to be working. Sure the first visit is slow, but the next time you load the page the page loads much faster.