Page MenuHomePhabricator

2% of load.php spent creating DBLoadBalancerFactory in WebStart.php
Open, HighPublic

Description

Unconditionally, on all web requests (including api.php, rest.php, load.php, etc.) we create the DBLoadBalancerFactory service in order to inject some request-specific meta data:

includes/Setup.php
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [

] );

To construct the DBLoadBalancerFactory service, it:

  • creates LBFactory
  • creates WANObjectCache
  • creates getStatsdDataFactory
  • creates and initialises MemcachedPeclBagOStuff

Let's look at what these constructors are doing and defer what we can so that the instantiation is a cheap as it can be.

Event Timeline

Krinkle created this task.Jul 24 2019, 3:48 PM
Restricted Application added a project: Core Platform Team. · View Herald TranscriptJul 24 2019, 3:48 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle triaged this task as High priority.Jul 25 2019, 9:18 PM

As most things from T189966, this would be nice to resolve before the new rest.php entrypoint goes live.

Change 532367 had a related patch set uploaded (by TK-999; owner: TK-999):
[mediawiki/core@master] rdbms: Defer instantiating the DBLoadBalancerFactory service

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

TK-999 added a subscriber: TK-999.Aug 26 2019, 12:34 PM

I've just uploaded a patch to defer this explicit instantiation. However, the DBLoadBalancerFactory will still be implicitly instantiated on every request if MediaWiki is configured to use a shared database, due to the following:

includes/Setup.php
if ( $wgSharedDB && $wgSharedTables ) {
	// Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
	MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
		array_fill_keys(
			$wgSharedTables,
			[
				'dbname' => $wgSharedDB,
				'schema' => $wgSharedSchema,
				'prefix' => $wgSharedPrefix
			]
		)
	);
}

I feel this should be handled separately.