Page MenuHomePhabricator

Check math BagOStuff cache
Closed, ResolvedPublic

Description

In

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/975432/12/src/MathRenderer.php#248

we switched from DB to BagOStuff cache for math.
This should now be deployed everywhere.

@thesocialdev In our email conversation, I referred to the plan to switch to this cache. Could you investigate if that cache is used? It should be used in the German Wikipedia when you log in and change the math rendering mode to MathML (experimental).

Event Timeline

I tried to dig around Grafana's BagOStuff dashboard "by keygroup" to see if I can find something related to Math* keygroup but didn't find anything. For example: https://grafana.wikimedia.org/d/4plhqSPGk/bagostuff-stats-by-key-group?var-kClass=MathRenderer

I'm not sure the cache is being used yet. Can we actually trigger this on German WP? to see if we can get some writes to the cache backend then see if that reflects on Grafana?

Let me know if this helps at all.

@DAlangi_WMF thank you for looking into this. It should be already used on WMDE and be triggered. You can visit any page with math. Unfortunately, they all render quite fast, so it's hard to tell if cache is used.

When I was trying this locally the full namespace was prefixed to the cache key.

https://github.com/wikimedia/mediawiki-extensions-Math/blob/45279fa678ac657b71286c601abacead1cbfae4b/src/InputCheck/LocalChecker.php#L103

Optimally it would use LocalChecker as class name.

@DAlangi_WMF thank you for looking into this. It should be already used on WMDE and be triggered. You can visit any page with math. Unfortunately, they all render quite fast, so it's hard to tell if cache is used.

There are ways to double check, can you give me a link to a page I can test?

I created a page that everyone can test (even without changing preferences) https://de.wikipedia.org/wiki/Benutzer:Physikerwelt/NativeTest

I don't see any calls to that system (https://logstash.wikimedia.org/goto/a320f7f412a405e16722862a785cd60f), maybe it's cached in another layer.

Maybe this could help you figure out what's not working: https://performance.wikimedia.org/excimer/profile/2a392df184f9ca6d

Edit correct link: https://performance.wikimedia.org/excimer/profile/cb3ff24fb1175566

I don't see any calls to that system (https://logstash.wikimedia.org/goto/a320f7f412a405e16722862a785cd60f), maybe it's cached in another layer.

Maybe this could help you figure out what's not working: https://performance.wikimedia.org/excimer/profile/2a392df184f9ca6d

I took another direction - testing this locally with PHPStorm + Xdebug (and break points) and I don't seem to hit that particular code path (cache writes with BagOStuff) as well. So that's another confirmation that cache writes are not happening.

NOTE: Locally, I'm using CACHE_DB and checking the DB objectcache table, I don't see anything matching the keygroup we're concerned with. See my settings below.
$wgMainCacheType = CACHE_ANYTHING;
$wgObjectCaches[CACHE_DB] = [
	'class' => SqlBagOStuff::class,
	'server' => [
		'host' => $wgDBserver,
		'dbname' => $wgDBname,
		'user' => $wgDBuser,
		'password' => $wgDBpassword,
		'type' => $wgDBtype,
		'flags' => 0,
	]
];

For local testing I was using

$wgMainCacheType = CACHE_DB;

and got key values of the form WANCache:global:MediaWiki\Extension\Math\InputCheck\LocalChecker:4f137411566a0a8cf5bbef2628bdc3b9|#|v

Screenshot 2024-01-23 at 22.43.18.png (584×2 px, 425 KB)

I don't know the Math code very well so I might be very wrong here but LocalChecker doesn't seem to be a subclass of MathRenderer and thus wouldn't be used for what DB was used before (possibly a different cache for a different thing?) I'm referring to https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/975432/12/src/MathRenderer.php#614 (::getCacheKey() which uses the class name)

if you're looking at the local checker, they do exist and they are everywhere (https://grafana.wikimedia.org/d/lqE4lcGWz/wanobjectcache-key-group?var-kClass=MediaWiki_Extension_Math_InputCheck_LocalChecker&orgId=1&from=now-7d&to=now and in the logstash I linked above)

Am I missing something super obvious?

I don't know the Math code very well so I might be very wrong here but LocalChecker doesn't seem to be a subclass of MathRenderer and thus wouldn't be used for what DB was used before (possibly a different cache for a different thing?) I'm referring to https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/975432/12/src/MathRenderer.php#614 (::getCacheKey() which uses the class name)

This is also good and expected (as we use the restbase).

if you're looking at the local checker, they do exist and they are everywhere (https://grafana.wikimedia.org/d/lqE4lcGWz/wanobjectcache-key-group?var-kClass=MediaWiki_Extension_Math_InputCheck_LocalChecker&orgId=1&from=now-7d&to=now and in the logstash I linked above)

This is very good and expected. In particular, the page https://de.wikipedia.org/wiki/Benutzer:Physikerwelt/NativeTest should at rendering call the cache above.

Am I missing something super obvious?

However, it does not explain why we had hits to the mathoid table before. One would expect that those read requests to the database table translate into get requests for keys that do not exist.

Physikerwelt added a subscriber: Marostegui.

Following the stack trace in T355346

#8 /srv/mediawiki/php-1.42.0-wmf.13/extensions/Math/src/MathRenderer.php(594): MediaWiki\Extension\Math\MathRenderer->readFromDatabase()
#9 /srv/mediawiki/php-1.42.0-wmf.13/extensions/Math/src/HookHandlers/ParserHooksHandler.php(118): MediaWiki\Extension\Math\MathRenderer->checkTeX()
#10 /srv/mediawiki/php-1.42.0-wmf.13/extensions/Math/src/HookHandlers/ParserHooksHandler.php(161): MediaWiki\Extension\Math\HookHandlers\ParserHooksHandler->mathPostTagHook(MediaWiki\Extension\Math\MathMathML, Parser)

it would be expected that not line 248 in math renderer would be called but line 190

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/975432/12/src/MathRenderer.php#190

$rpage = $this->cache->get( $this->getCacheKey() );

My theory is that \WANObjectCache::get does not generate log data for missed cache entries. In addition, no new entries will be created as the last newly created entry in the table was from years ago.

For what is worth the table was last written on 14th July 2020

I'll close this for now as it appears to me that everything is as it should be. Please reopen, if the theory does not seem plausible.

PS: One could say that checking the mathoid table does not make sens in combination with restbase cache, but as this will change anyhow, I think we can ignore this for now.