Page MenuHomePhabricator

Growth features is making a lot of db queries in every pageview regardless of user's status
Closed, ResolvedPublic

Description

I've been auditing db queries of common/typical request and opening article of Alan Turing in mobile (with warm ParserCache and APCu cache) returns 85 db queries. List of them. Out of which these seem to be related to Growth features (in reverse chronological order):

Wikimedia\Rdbms\SelectQueryBuilder [0.001s] db1135: SELECT  actor_name AS `value`  FROM `actor`    WHERE actor_name IN ('Xaosflux','Xaosflux ep')  AND (actor_user != 0)  

WikiPage::pageData [0.001s] db1135: SELECT  page_id,page_namespace,page_title,page_restrictions,page_is_redirect,page_is_new,page_random,page_touched,page_links_updated,page_latest,page_len,page_content_model  FROM `page`    WHERE page_namespace = 4 AND page_title = 'Growth_Team_features/Mentor_list/Manual'  LIMIT 1  

Wikimedia\Rdbms\SelectQueryBuilder [0.005s] db1135: SELECT  actor_name AS `value`  FROM `actor`    WHERE actor_name IN ('Sungodtemple','Sdkb','Wugapodes','Nosebagbear','Ahmetlii','Ipigott','Em-mustapha','Bsoyka','Ampimd','Tol','Pelagic','Calliopejen1','Berrely','Bilorv','Elli','DanCherek','ARoseWolf','GenQuest','Eddie891','Qwerfjkl','CaptainEek','Dreamy Jazz','Lajmmoore','Ezlev','Pahunkat','Vukky','EpicPupper','Zoozaz1','TheSandDoctor','Pbsouthwood','Sennecaster','TheresNoTime','Chlod','JavaHurricane','Extraordinary Writ','I dream of horses','Asartea','Blaze Wolf','Ganesha811','Justiyaya','LEvalyn','Michael D. Turnbull','Panini!','Pyrrho the Skeptic','Rotideypoc41352','SCHolar44','Trialpears')  AND (actor_user != 0)  

WikiPage::pageData [0.001s] db1135: SELECT  page_id,page_namespace,page_title,page_restrictions,page_is_redirect,page_is_new,page_random,page_touched,page_links_updated,page_latest,page_len,page_content_model  FROM `page`    WHERE page_namespace = 4 AND page_title = 'Growth_Team_features/Mentor_list'  LIMIT 1  

(The same happens three times more)

It basically makes four queries three duplicate times (12 times) in every page view. I checked and I haven't enabled growth features in enwiki neither as mentor nor mentee. It needs to at least cache queries inside one request and do not run these queries for people who are not signed on as mentee/mentor.

Here is the XHGui: https://performance.wikimedia.org/xhgui/run/view?id=61c0e37053a0c7a56aa214b3 (callgraph)

I see this WikiPageConfigLoader::load being called 12 times and its cache is a BagOStuff which is just inside request and not persistent (not even inside request unless you make it a singleton) might be related, might not. If it's a config and stays the same per wiki, just use MediaWikiServices::getLocalServerObjectCache

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Urbanecm_WMF added a subscriber: Urbanecm_WMF.

Sounds to be caused by the checks made in MentorDashboardDiscoveryHooks::isDiscoveryEnabled. We should add some caching to MentorPageMentorManager::getMentorsForPage to fix this.

I see this WikiPageConfigLoader::load being called 12 times and its cache is a BagOStuff which is just inside request and not persistent (not even inside request unless you make it a singleton) might be related, might not. If it's a config and stays the same per wiki, just use MediaWikiServices::getLocalServerObjectCache

This is actually not relevant. The HashBagOStuff in it is overriden in ServiceWiring.php.

Change 748827 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/GrowthExperiments@master] MentorPageMentorManager: Cache getMentorsForPage

https://gerrit.wikimedia.org/r/748827

Change 749905 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/GrowthExperiments@master] Rewrite MentorManager caching

https://gerrit.wikimedia.org/r/749905

Change 749905 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Rewrite MentorManager caching

https://gerrit.wikimedia.org/r/749905

Tgr added subscribers: Etonkovidova, Tgr.

@Etonkovidova not really QA-able, just FYI: changes to the list of mentors might take up to 5 minutes to take effect once the patches are deployed.

Change 748827 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] MentorPageMentorManager: Cache getMentorsForPage

https://gerrit.wikimedia.org/r/748827

This is live for a full train now. Tentatively closing.

@Ladsgroup, please feel free to review the number of queries that are made by the Growth features again, and reopen/fill a new task if we need to improve anything.

Thanks. I do regular audits from time to time and will let you know if I find anything.