Directory

⚓ T208430 Calculating statistics for core-0-mostused is really slow
Page MenuHomePhabricator

Calculating statistics for core-0-mostused is really slow
Closed, ResolvedPublic2 Estimated Story PointsBUG REPORT

Description

It also uses a lot of CPU, which seems to indicate there is something really inefficient going on there.

Event Timeline

To reproduce: MessageGroupStats::forGroup( 'core-0-mostused', MessageGroupStats::FLAG_NO_CACHE );

Nikerabbit raised the priority of this task from Low to Medium.Feb 11 2021, 2:23 PM

Caused issues today.

Caused issues today during testing. Job queue was stuck processing this.

Nikerabbit set the point value for this task to 2.

Job queue was stuck again, so I used xdebug profiling to investigate. Over half of the time was spent in MediaWikiTopMessageGroup->getTags.

Change 966508 had a related patch set uploaded (by Nikerabbit; author: Nikerabbit):

[translatewiki@master] Add tag cache to MediaWikiTopMessageGroup

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

Here's a screenshot of time profile with my suggested fix, from live environment (note that this is an incomplete run, I did Ctrl+C after 30 seconds or so).

image.png (1×2 px, 318 KB)

Change 966508 merged by jenkins-bot:

[translatewiki@master] Add tag cache to MediaWikiTopMessageGroup

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

New bottleneck is getDefinitions:

image.png (1×1 px, 179 KB)

Still takes 30 minutes which is more than I'd like.

Change 966515 had a related patch set uploaded (by Nikerabbit; author: Nikerabbit):

[mediawiki/extensions/Translate@master] Add SubsetMessageGroup

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

Nikerabbit changed the subtype of this task from "Task" to "Bug Report".

Change 966515 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] Add SubsetMessageGroup

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

cat debug.php 
MessageGroupStatsRebuildJob::newRefreshGroupsJob( [ 'core-0-mostused' ] )->run();

time php /srv/mediawiki/workdir/maintenance/eval.php < debug.php 

*******************************************************************************
NOTE: Do not run maintenance scripts directly, use maintenance/run.php instead!
      Running scripts directly has been deprecated in MediaWiki 1.40.
      It may not work for some (or any) scripts in the future.
*******************************************************************************




real    0m31.487s
user    0m17.516s
sys     0m0.654s

30 seconds is much faster than 30 minutes (or multiple hours before the first improvement).

Found one instance from the logs how long the job would run:

Oct 17 10:45:07 web2.translatewiki.net php[211581]: 2023-10-17 08:45:07 MessageGroupStatsRebuildJob Special:MainPage cleargroups=["wikimedia-advanced","ext-0-wikimedia","ext-timedmediahandler-user","core-0-mostused","mediawiki","wikimedia-main","ext-0-all","ext-timedmediahandler"] namespace=-1 title=MainPage requestId=7d88edddbed20efa22c22c81 (id=89289724,timestamp=20231017084507) STARTING
Oct 17 22:16:40 web2.translatewiki.net php[211581]: 2023-10-17 20:16:40 MessageGroupStatsRebuildJob Special:MainPage cleargroups=["wikimedia-advanced","ext-0-wikimedia","ext-timedmediahandler-user","core-0-mostused","mediawiki","wikimedia-main","ext-0-all","ext-timedmediahandler"] namespace=-1 title=MainPage requestId=7d88edddbed20efa22c22c81 (id=89289724,timestamp=20231017084507) t=41493097 good

It's not direct comparison, but the running time of other things is marginal compared to this one, so roughly speaking we improved the job running time from 11 and half hours 30 seconds. Or relative speaking 99.93% improvement.