Hello, MediaWiki now has a dedicated lock (mutex https://en.wikipedia.org/wiki/Lock_(computer_science)) manager service (resolving this nine-year-old RfC https://phabricator.wikimedia.org/T161749) that you can now use. You can access this service by calling $services->getLockManager() in your code and it provides a narrow interface called ILockManager https://gerrit.wikimedia.org/g/mediawiki/core/+/master/includes/libs/LockManager/ILockManager.php. This also means calling Database::lock/unlock outside of DatabaseLockManager class is now deprecated and if your code in extensions uses that, please switch it to use the service instead.
On third party setups, this service can be changed to a different lock manager backend via a config variable (DefaultLockManager) and the default is the primary database but in our production it's set to a set of redis hosts (they have replication factor of 2, see the documentation https://wikitech.wikimedia.org/wiki/User:ASarabadani_(WMF)/Consistent_hashing_in_MediaWiki). And each host is now taking https://grafana.wikimedia.org/d/000000174/redis?orgId=1&from=now-12h&to=now&timezone=utc&var-job=redis_lock&var-site=codfw&var-site=eqiad&var-host=$__all&var-instance=$__all&var-role=$__all more than 3k reqs/s. Major thank you to SRE ServiceOps https://www.mediawiki.org/wiki/Wikimedia_Site_Reliability_Engineering#Service_Operations team for their work https://phabricator.wikimedia.org/T427999 in setting it up. This also means the dedicated redis setup for file backend is now being decommissioned https://phabricator.wikimedia.org/T435268.
The switch from database-backed lock manager to redis has reduced number of selects on primary databases by between 25 to 30% https://phabricator.wikimedia.org/T366938#12229060 which is quite important since primary databases are harder to scale (i.e. in one cluster, we can buy more replicas, we can't buy an extra primary) so more migration to use the lock manager service would lead to more reduction of the load on primary databases (and more stable database clusters).
Shout out to MediaWiki API Platform https://www.mediawiki.org/wiki/MediaWiki_Interfaces_Team team with their code review and help getting the MediaWiki patches off the ground.
Best
mediawiki-l@lists.wikimedia.org