Jump to content

Topic on Project:Support desk

Testing local Redis cache integration with MediaWiki

15
Summary by Nnaka1

@Bawolff Thanks for answering again!

Solution summary: enable debug logging in LocalSettings.php and check that redis is being used in the various caches that MediaWiki uses. (e.g. object cache, parser cache)

Force entries into the cache by executing something like this:

echo "MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache()->set( 'keyname', 'value' );" | php maintenance/eval.php

Nnaka1 (talkcontribs)

I have set up a local Redis instance with an open socket. I have followed the instructions here and have made changes in my LocalSettings.php to use it both as an object cache and job queue. However, I have not been seeing any objects or jobs appear when I view the cache contents. I was wondering what the best way to debug / test whether the MediaWiki instance is properly using the cache? Thanks!

My LocalSettings.php contains these configurations:

$'wgMainCacheType' = 'redis';

$'wgObjectCaches'['redis'] = [

'class'                => 'RedisBagOStuff',

'servers'              => [ '...redis.sock' ]

];

$'wgSessionCacheType' = 'redis';

$'wgJobTypeConf'['default'] = [

'class'          => 'JobQueueRedis',

  'redisServer'    => '...redis.sock',

  'redisConfig'    => [],

'claimTTL'       => 3600,

'daemonized'     => true

];

Bawolff (talkcontribs)

first step - enable mediawiki debug logging (see How to debug ) the debug log should list which cache is in use for various things and any errors.

Make sure that "...redis.sock" is correct syntax (i dont know if its right or not. Dont know that much about redis)

Nnaka1 (talkcontribs)

Thanks, @Bawolff!

Following your suggestion, I enabled the debug logging and am seeing the following:

[objectcache] MainWANObjectCache using store RedisBagOStuff

[MessageCache] MessageCache using store RedisBagOStuff

[MessageCache] MessageCache::load: Loading en... local cache is empty, got from global cache

[caches] parser: RedisBagOStuff

Article::view using parser cache: yes

Parser cache options found.

ParserOutput cache found.

Article::view: showing parser cache contents

Which suggests that the redis cache is indeed up. I was wondering whether there is a deterministic way to populate the cache to confirm that it is working as expected.

I tried something simple like refreshing the page to see whether the MessageCache would no longer need to fall back to the "global cache", which I am assuming here refers to the DB.

Bawolff (talkcontribs)

well its saying its serving the current page out of parser cache, and parser cache is backed by redis, so that should mean its populated.

For message cache, not sure, but local cache might mean APCu and global cache redis.

Nnaka1 (talkcontribs)

Thanks for the answer, @Bawolff

Is there a way to force Redis to populate for the different caches (e.g. object, message, and parser).

Based on what you said, I'm quite confident now that the cache is connecting, but for some reason I'm still not seeing any keys appear in the cache, which makes me want to confirm that writing to it is working as expected.

Bawolff (talkcontribs)

you could use eval.php

MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache()->get( 'keyname');

And

echo MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache()->set( "keyname", "value" );

Nnaka1 (talkcontribs)

Yes, that worked! Also, from playing around, it seems like logging in as the admin and loading / reloading a number of the pages seemed to populate the cache with a few hundred keys.

Keepersdungeon (talkcontribs)

Hello been trying to config Redis for mediawiki 1.41.2 recently but i'm getting

Fatal error: Uncaught error: Class "wikimedia\IPUtils" not found when I run jobrunner as suggested Here on Redis Page.

I've posted my setting here if anyone would like to take a look.

Did u have any issues when u run "php redisJobChronService --config-file=config.json" ?

Bawolff (talkcontribs)

For the fatal error, did you run composer install?

Keepersdungeon (talkcontribs)

Not sure I follow, the command I ran from a terminal in Cpanel. But I used composer to install semantic mediawiki.

You mean should I run composer

php composer.phar update --no-dev

beforehand?

Bawolff (talkcontribs)

Yes, in the directory the job runner service is in.

Keepersdungeon (talkcontribs)

The error is gone but when I run php redisJobChronService --config-file=config.json nothing seems to happen it just stays at NOTICE: Starting job chron loop(s)...

Should I change the dispatcher in the config.json from "nothing" to link to runJobs.php file?

Keepersdungeon (talkcontribs)

if I run php redisJobChronService --config-file=config.json --verbose I get the following messages that gets repeated infinitely

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: get ["RedisJobChronService::executePeriodicTasks:lock:0"]

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: getset ["RedisJobChronService::executePeriodicTasks:lock:0",1723022498.49072]

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: sMembers ["global:jobqueue:s-queuesWithJobs"]

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: hMSet ["jobqueue:aggregator:h-ready-queues:v2:temp",{"_epoch":1723022498}]

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: rename ["jobqueue:aggregator:h-ready-queues:v2:temp","jobqueue:aggregator:h-ready-queues:v2"]

2024-08-07T09:21:38+00:00 DEBUG: Redis cmd: del ["RedisJobChronService::executePeriodicTasks:lock:0"]

2024-08-07T09:21:39+00:00 DEBUG: Memory usage: 683848 bytes.


Same for php redisJobRunnerService --config-file=config.json --verbose I get these repeating infinetly

2024-08-07T09:20:56+00:00 DEBUG: Redis cmd: hGetAll ["jobqueue:aggregator:h-ready-queues:v2"]

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:56+00:00 DEBUG: No jobs available...

2024-08-07T09:20:57+00:00 DEBUG: No jobs available...

2024-08-07T09:20:57+00:00 DEBUG: No jobs available...

2024-08-07T09:20:57+00:00 DEBUG: No jobs available...

Keepersdungeon (talkcontribs)

And I also have another question regarding this part

Configure a daemon to run this at server start:

php redisJobChronService --config-file=config.json

How can I configure a daemon to run this?

Apologies in advance for all those questions but it's all a bit confusing if you don't have much experience in this

94.134.181.32 (talkcontribs)

Hi, ich have the same problem, when I run php redisJobChronService --config-file=config.json nothing seems to happen it just stays at NOTICE: Starting job chron loop(s)..., event when i changed the "nothing" to the runJobs.php path in the config.json. Have you already solved the problem?

Reply to "Testing local Redis cache integration with MediaWiki"