Too many DB queries for _conditions table when...

Search
Other Bug Reports questions
Forum

Too many DB queries for _conditions table when using AMM on J4

Redaktor's Avatar Redaktor
Hello!
I would like to ask for advice/help with the following problem:
After installing AMM on pure J4, the number of queries to the DB is multiplied by about 4x, but on the production site (updated J3 to J4) with articles and modules, queries take 4-5 seconds! and only then the content is displayed.
Approximately 6,000 queries are made to the database to display a page with 10 modules. Most of the questions are about tables:
_conditions*
_modules

The same page (with AMM used) on J3 needs about 250 queries to display.

Please do you know what is causing this problem and how to fix it?
Thank you in advance for your reply,
Peter
Peter van Westen's Avatar Peter van Westen ADMIN
Hmmm, not sure why that is happening. In most cases the Joomla 4 version should use less queries.

Can you give me (super) admin and (s)ftp access so I can take a look?
And tell me on what url I can see/reproduce the issue.
And which modules (IDs) are causing these queries.
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Redaktor's Avatar Redaktor
Hi,
Thank you for your response. Unfortunately, the website is not accessible from the world. I have to wait for the DNS to be made available/set up and that won't be possible until Monday.
For now I can send query/sql_log for download:
Confidential information:
(hidden)

Thank you, Peter
Peter van Westen's Avatar Peter van Westen ADMIN
I can't tell much from that without context.
If you can reproduce this on an online environment to which I can get access, I am happy to look into this.
Please post a rating at the Joomla! Extensions Directory
Redaktor's Avatar Redaktor
Confidential information:
(hidden)

Thank you, Peter
Peter van Westen's Avatar Peter van Westen ADMIN
And tell me on what url I can see/reproduce the issue.
And which modules (IDs) are causing these queries.
I would also need the (s)ftp access...
Please post a rating at the Joomla! Extensions Directory
Redaktor's Avatar Redaktor
Confidential information:
(hidden)
Redaktor's Avatar Redaktor
Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
I am currently on holiday, traveling around. So I can't say what IP address I will have at any point.
I'll be back home with a fixed IP address in about 2 weeks.
Please post a rating at the Joomla! Extensions Directory
Gary Brindley's Avatar Gary Brindley
Hi

I can confirm that this is an issue.

J3 site with AMM has ~300 queries on the homepage.

Migrating to J4 ups this to 4200. Disabling AMM drops back to about 300.

In our testing it looks like AMM is querying all modules on every page. Meaning as your usage of modules grows, site-wide performance gets progressively worse.

I've tested this by creating a fresh J4 install with AMM. Standard out the box config. Adding modules and using menu item assignments on other pages increases queries on the homepage. We added 10 modules to other pages, with the same condition, and it added 30 queries to the homepage.

Disabling AMM drops this by about 100 queries. Core joomla module manager is not checking every module per page so I hope that AMM can be updated to behave in a more performant fashion.

Otherwise this makes AMM impossible to use for medium+ sized websites. We are seeing negative performance implications on the J3 and 4 versions of the site in question using AMM.

Please advise.
Peter van Westen's Avatar Peter van Westen ADMIN
I will have to look into this.
It is correct that it has to check all modules on every page whether it should show or not.
But this shouldn't result in so many queries. So not sure what is going on there.

Can you give me (super) admin and (s)ftp access so I can take a look?
And tell me on what url I can see/reproduce the issue.
You can use the 'Confidential information' button in the forum editor to hide sensitive information.

My current IP: 63.250.57.234
Please post a rating at the Joomla! Extensions Directory
Gary Brindley's Avatar Gary Brindley
Hi Peter

Thanks for the speedy response. Core Joomla module manager does not check every module on every page. While I appreciate you're saying it shouldn't generate so many queries, it's still a long term performance issue. Some of our websites have 600-1000 modules and so unless this can be improved, we're going to have to stop using AMM as we transition to J4.

I understand why it needs to check every module if there isn't a menu item assignment set. Unfortunately we've proved that even with menu item assignment, AMM checks every module for every page - which seems unnecessary since core joomla doesn't do this.

For the 4200 queries issue, please see your access information below. We have left debugging on so you can see the query trace at end of page.

Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
Core module manager also needs to see whether a module should show up on a page. But it does this within a single query. As it only needs to check the menu assignment (and publishing dates, and language, and access level).

With the conditions/assignments, it's a whole other ball game.

I have been able to get it down a bit (from 4364 to 2565).
The issue is not so much that you have a lot of modules, but that you have a lot of Condition Sets.
Every module now has its own Condition Set, while many are duplicates.
I would recommend you look into using just 1 Condition Set for every unique set of rules.

If AMM checks a condition set for a certain module, it doesn't need to check that again for any other modules using that same set.
2 Condition Sets with exactly the same rules is not seen as the same set, though.
Please post a rating at the Joomla! Extensions Directory
Gary Brindley's Avatar Gary Brindley
Morning Peter

Thanks for this, but unfortunately this does not help.

To address the 4200 queries - we used your migration process to upgrade from AMM 7 to 9 (for the J4 migration). It's this process which has created all the individual conditions. How do we prevent this? We cannot manually update hundreds of modules for each website we need to migrate, and if your migration process does not properly set up conditions then what do we do?

In addition, we have tested the single condition assignment on our fresh J4 and it still impacts other pages. Creating 10 modules with the same condition adds 30 queries to every page.

This isn't acceptable at scale, please advise.
Peter van Westen's Avatar Peter van Westen ADMIN
The conversion script should not duplicate conditions that have exactly the same rules.
This seems to go wrong. So I will try to fix that asap.

I'll also look into seeing where the extra database queries come from and if I can reduce this.
30 queries isn't necessarily bad, if these are light-weight queries.
And adding modules using the same condition set should not add extra queries (coming from AMM).
I'll do some more testing on this on my side.

I won't have a quick fix for you.
I hope to have this sorted within a week or 2.
Please post a rating at the Joomla! Extensions Directory
Gary Brindley's Avatar Gary Brindley
A week or two is a quick fix in my book! Thanks very much Peter, please let me know if you would like any further access to anything. Will leave your access to the 4200 query site in case you'd like to try anything there.

Please keep us in the loop

Thanks
Peter van Westen's Avatar Peter van Westen ADMIN
Yup, will do...
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
Can you try to redo the conversion of the modules from your Joomla 3 setup with the new dev version?

If you don't want to. do the whole conversion of the entire site, you can just do this for the AMM part:

Delete these tables:
..._advancedmodules
..._conditions
..._conditions_groups
..._conditions_rules
..._conditions_map
Then copy over the ..._advancedmodules table from your Joomla 3 database to the Joomla 4 database.

After that, install the latest development version of AMM from:
regularlabs.com/development-releases

It should now not create duplicate Condition Sets of modules with the same assignments.
Which should result in a LOT less queries.
Please post a rating at the Joomla! Extensions Directory
Gary Brindley's Avatar Gary Brindley
Hi Peter

Thank you for this. While this version has certainly addressed some issues, I unfortunately think this may still be unusable for us.

We reset our test site and followed your instructions. The upgrade now produces ~2100 queries on the homepage, down from 4200. These 2100 queries are still using a lot of memory and response time is sluggish. ~59-66MB mem to execute the queries and they complete in 0.8s

We tested adding modules to other pages and while the impact site-wide is less, it still adds queries to other pages.

Do you think this is "as good as it's going to get" ? I still keep coming back to the fact that Joomla core module manager doesn't need to check every module/condition/rule. I appreciate the differences between it and AMM but surely there's some middle ground - having thousands of queries on every page now seems unavoidable for large sites using AMM. What are your thoughts? Your access has been left on our test site if you'd like to take another look. If we've misused or misconfigued something I would welcome a correction.

Right now I think we're going to have to sadly ditch AMM (after years! :'( ) and write our own plugin to build on joomla's module manager since it is more performant at scale. I would much rather keep using AMM if there's a way around this that is beneficial to all your users.

Thanks again for your time and help Peter.
Peter van Westen's Avatar Peter van Westen ADMIN
Well, do you have hundreds of different Condition Sets?
Or are there still a lot of duplicate Condition Sets.
If so, then the conversion is still not as it should.

Generally speaking there are 4 lightweight queries per Condition Set. With a lot of effort I could maybe see if I can somehow combine some of these. But I am not sure that would make much of a speed difference (4 light queries vs 2 more complex queries).
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in