Setting up the Redis queue for postActiv

postActiv redis queue

The default queue used in postActiv and GNU Social is OpportunisitcQM, which is backed by MySQL. This works well for sites with small loads, but can become a bottleneck for larger sites.

However, postActiv can work with other backends such as Redis or a STOMP server. I'll be focusing on the former as there's an excellent guide to setting up STOMP.

Disclaimer: This option is limited to postActiv instances only, since GNU Social doesn't have the Redis queue implemented. If you are running vanila GNU Social, you'll either need to switch to postActiv or use the STOMP queue using the guide above.

Installing dependencies

Of course, the first thing is to install the necessary packages like Redis.

For Ubuntu/Debian:

sudo apt-get install redis-server php-redis

Note: replace with php5-redis if on something earlier than Debian 9/Ubuntu 16.04

For CentOS:

sudo yum install epel-release
sudo yum install redis php-pecl-redis php-gmp

Before enabling Redis, make sure it only listens to localhost connections. Make sure this line is in /etc/redis.conf:

bind 127.0.0.1

Enable and start Redis once you make sure that setting is correct:

sudo systemctl enable redis-server
sudo systemctl start redis-server

Setting up Redis in postActiv

You will need to tweak your postActiv configuration before you can reap the benefits of the Redis queue. Add/edit the following lines in config.php:

$config['ostatus']['hub_retries'] = 3;

$config['queue']['enabled'] = true;
$config['queue']['daemon'] = true;
$config['queue']['subsystem'] = 'redis';
$config['queue']['redis_host'] = '127.0.0.1';
$config['queue']['redis_namespace'] = 'gs';
$config['queue']['redis_retries'] = 5; // Just needs to be more than $config['ostatus']['hub_retries']
$config['queue']['redis_expiration'] = 43200; // half day

Once you're done, start the queues:

su - www-data bash -c "script/startdaemons.sh" # replace www-data with php-fpm if on CentOS

This should be it for enabling the Redis queue backend for postActiv.