Manual:$wgLBFactoryConf/de-formal

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
<translate> LoadBalancer settings</translate>: $wgLBFactoryConf
Configuration for the ILBFactory service
<translate> Introduced in version:</translate>1.13.0 (r32578)
<translate> Removed in version:</translate><translate> still in use</translate>
<translate> Allowed values:</translate>(array)
<translate> Default value:</translate>(see below)

Details

To set up a multi-primary (formerly called multi-master) wiki farm, set the class here to something that can return a Wikimedia\Rdbms\LBFactory with an appropriate primary on a call to getMainLB(). The class identified here is responsible for reading $wgDBservers , $wgDBserver , etc., so overriding it may cause those globals to be ignored.

The Wikimedia\Rdbms\LBFactoryMulti class is provided for this purpose, the configuration for this class is provided below:

File:OOjs UI icon notice-destructive.svg <translate> Warning:</translate> If you use this class, all previous settings like $wgDBservers , $wgExternalServers , ... will be ignored.
sectionsByDB
A map of database names to section names
sectionLoads
A 2-d map. For each section, gives a map of server names to load ratios. For example: array( 'section1' => array( 'db1' => 100, 'db2' => 100 ) )
serverTemplate
A server info associative array as documented for $wgDBservers. The host, hostName and load entries will be overridden.
groupLoadsBySection
A 3-d map giving server load ratios for each section and group. For example: array( 'section1' => array( 'group1' => array( 'db1' => 100, 'db2' => 100 ) ) )
groupLoadsByDB
A 3-d map giving server load ratios by DB name.
hostsByName
A map of hostname to IP address.
externalLoads
A map of external storage cluster name to server load map
externalTemplate
A server info structure used for external storage servers
templateOverridesByServer
A 2-d map overriding mainTemplate or externalTemplate on a server-by-server basis.
templateOverridesByCluster
A 2-d map overriding externalTemplate by cluster
masterTemplateOverrides
An override array for mainTemplate and externalTemplate for all primary servers.

Default values

<td class="mw-version-versionbox" title="<translate nowrap> The latest stable version is <tvar name=1>1.41</tvar></translate>">
<translate> ≥</translate> 1.39
<translate> MediaWiki version:</translate>
$wgLBFactoryConf = [
	'class' => 'Wikimedia\\Rdbms\\LBFactorySimple',
];
<td class="mw-version-versionbox" title="<translate nowrap> MediaWiki <tvar name=1>1.38</tvar> is unsupported version</translate>">
1.31 – 1.38
<translate> MediaWiki versions:</translate>
$wgLBFactoryConf = [ 'class' => \Wikimedia\Rdbms\LBFactorySimple::class ];
<td class="mw-version-versionbox" title="<translate nowrap> MediaWiki <tvar name=1>1.30</tvar> is unsupported version</translate>">
1.23 – 1.30
<translate> MediaWiki versions:</translate>
$wgLBFactoryConf = [ 'class' => 'LBFactorySimple' ];
<td class="mw-version-versionbox" title="<translate nowrap> MediaWiki <tvar name=1>1.22</tvar> is unsupported version</translate>">
1.13 – 1.22
<translate> MediaWiki versions:</translate>
$wgLBFactoryConf = array( 'class' => 'LBFactory_Simple' );

Simple Examples

3 wikis all using localhost as db server

Here is how a simple configuration would work, where you have three wikis (wikidb1, wikidb2 and wikidb3), all of which using the same database server (but with different database names), and all of them having a single primary server which is the same as your webserver (localhost)

$wgDBuser = 'your db username'; //must be same for all 3 wikis in this simplified setup
$wgDBpassword = 'pass'; // Same pass must be usable for all 3 wikis
$wgLBFactoryConf = array(

'class' => 'LBFactoryMulti',

'sectionsByDB' => array(
    'wikidb1' => 's1', // Assumes db name for first wiki is wikidb1
    'wikidb2' => 's1', // and so on.
    'wikidb3' => 's1',
),

'sectionLoads' => array(
    's1' => array(
        'localhost'  => 0, // All on section s1, which has single primary, at localhost.
    ),
),


'serverTemplate' => array(
    'dbname'      => $wgDBname,
    'user'          => $wgDBuser,
    'password'      => $wgDBpassword,
    'type'          => 'mysql',
    'flags'          => DBO_DEFAULT,
    'max lag'      => 30,
),
);

3 wikis using different hosts as db and one replica database

Say your wiki has grown a bit. Lets say you want to separate your db server from your webserver. And you have a replica server for which you have set up replication. And you now put wikidb3 on an entirely separate server.

So say we have wikidb1 and wikidb2 share a primary server (db1) and a replica (db2). Wikidb3 has its own db server db3 (and no replica). You would do something like:

$wgDBuser = 'your db username'; //must be same for all 3 wikis in this simplified setup
$wgDBpassword = 'pass'; // Same pass must be usable for all 3 wikis
$wgLBFactoryConf = array(

'class' => 'LBFactoryMulti',

'sectionsByDB' => array(
    'wikidb1' => 's1', // Assumes db name for first wiki is wikidb1
    'wikidb2' => 's1', // and so on.
    'wikidb3' => 's2',
),

'sectionLoads' => array(
    's1' => array(
        'db1'  => 0,
        'db2'  => 50, /* the 50 is the weight (of replica servers). Would matter if you had multiple */
    ),
    's2' => array(
        'db3' => 0
    ),
),


'serverTemplate' => array(
    'dbname'      => $wgDBname,
    'user'          => $wgDBuser,
    'password'      => $wgDBpassword,
    'type'          => 'mysql',
    'flags'          => DBO_DEFAULT,
    'max lag'      => 30,
),
);

Wikimedia configuration

To see how Wikimedia uses $wgLBFactoryConf to configure its wikis see:

Much of the information in this file has been moved into an etcd (key-value) store. For an older example see e.g. db-eqiad.php from 2019.

Wikimedia configuration uses also $wgCdnReboundPurgeDelay .