Redis + XON redis slow initial site loads

NealC

Well-known member
I'm running ubuntu server 20.04 on a powerful server (dual proc raid 10 SSD's 512 GB RAM, etc.) I have 6 XF 2.2 sites on this server, none of which are majorly active but steady. I've noticed when going to the site after a period of time or on a different browser, etc. there may be an initial delay of up to 20 seconds before the site shows. It's rare that this happens but it happens often enough to catch my attention and I've had a few users now report the same. I made a few changes, monitored, no improvement, then finally disabled redis cache and also the XON add-in for it and the problem appears to have completely gone away. I read that redis cache is single threaded and wonder if that's the problem, are we waiting for a lock to release or something? Is redis not the preferred option? I'm new to ubuntu server coming from Windows Server 2019. I'd like to have a good cache setup IF it will improve the site but for now it seems disabling redis is a better option and maybe I should consider a different cache or I'm doing something wrong with redis config. Here is my config.php contents for redis.

PHP:
$config['cache']['enabled'] = false;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
    'server' => '127.0.0.1',
    'port' => '6379',
    'compress_data' => 6,
    'password' => 'removed',
    'database' => 5
);
 
i've never seen a 20 second wait - let alone a 1 second wait - with either product and have been running both for a few years now.


your config file is missing all the elements to cache (Css, js, etc) and doesn't have a timeout which could be the defaulting you are seeing. if it can't get the cache quick, move on.


mine looks like

Code:
//REDIS CACHE / XON Add on
// setup redis caching
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';

// all keys and their defaults
$config['cache']['config'] = array(
        'server' => '127.0.0.1',
        'port' => 6379,
        'timeout' => 2.5,
        'persistent' => null,
        'force_standalone' => false,
        'connect_retries' => 1,
        'read_timeout' => null,
        'password' => REMOVED,
        'database' => 0,  //unique for each key
        'compress_data' => 1,
        'lifetimelimit' => 2592000,
        'compress_threshold' => 20480,
        'compression_lib' => null, // dynamically select first of; snappy,lzf,l4z,gzip IF EMPTY/null
        'use_lua' => true,
        'serializer' => 'igbinary', // to disable set to 'php'
        'retry_reads_on_master' => false,
        );


// START CSS caching //
$config['cache']['css'] = true;

$config['cache']['context']['css'] = [       
    'namespace' => 'svcss',
    'provider' => 'SV\RedisCache\Redis',
    'config' => [
            'server' => '127.0.0.1',
            'port' => 6379,
            'database' => 1,
            'connect_retries' => 1,
            'use_lua' => true,
            'compress_data' => 0,
            'read_timeout' => 1,
            'timeout' => 1,
            'serializer' => 'igbinary',
            'persistent' => true,
        ],
     ];
// END CSS caching //

// START session caching //
$config['cache']['sessions'] = true;
$config['cache']['context']['sessions'] = [       
    'namespace' => 'svsess',
    'provider' => 'SV\RedisCache\Redis',
    'config' => [
            'server' => '127.0.0.1',
            'port' => 6379,
            'database' => 2,
            'connect_retries' => 1,
            'use_lua' => true,
            'compress_data' => 0,
            'read_timeout' => 1,
            'timeout' => 1,
            'serializer' => 'igbinary',
            'persistent' => true,
            ],
        ];
// END session caching //

// START registry caching //
$config['cache']['registry'] = true;
$config['cache']['context']['registry'] = [       
    'namespace' => 'svregistry',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
            'server' => '127.0.0.1',
            'port' => 6379,
            'database' => 3,
            'connect_retries' => 1,
            'use_lua' => true,
            'compress_data' => 0,
            'read_timeout' => 1,
            'timeout' => 1,
            'serializer' => 'igbinary',
            'persistent' => true,
            ],
        ];
// END registry caching //
 
So far so good on https://rvforums.com. I had to put my password property into each of the config sections, for anyone else that copies the above. I'm not sure how the CSS caching compares to what I have in .htaccess that apache is using, if I can use both, should use both, one vs. the other.

Not sure if it's by design @Xon but now I see 4 separate Redis blocks in the admin, all showing identical info for each of the above config sections.

This setup is using 4 database nodes, I think there are only 16 available in Redis? Using this on multiple sites, I have 6, would be a problem? Or how do you do this?
 
I turned it back off. It seems web site speed tests are 12% better in overall score without it. I guess there is a point where it's a benefit, I'm not sure when that is. Right now it seems XF 2.2 is running optimally without it, at least in my setup.
 
you can control the databases with the database field flag. i broke it out for my set up.

you may not immediate see benefit of the cache as it has to cache everything first, then it becomes useful.

i would say give it more time to evaluate.
 
Should the be separate or share the same database? Should I use one database id for each site?
 
I'm not sure, but per the first comment block, it sounds like it should be unique per key.

so, i would say each site + each key needs its own db ID. but again, i'm not sure.
 
The caching setup doesn't need to be that complex.

In your case this is all that is needed;
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
    'server' => '127.0.0.1',
    'port' => '6379',
    'password' => 'removed',
];
  • $config['cache']['enabled'] = true;
    • Because otherwise the caching just isn't setup!
  • $config['cache']['sessions'] = true;
    • Use the caching backend for redis for sessions instead of the db
There isn't any point using separate databases. Setting up various cache-section configuration doesn't matter either if they are just talking to the one redis instance, this will just force more connections which is slower for no win.

One change I would recommend is to ensure the following php extensions are installed;
  • php-opcache
    • Some configurations may support installing php without opcache. This is dumb and throws away free performance.
  • php-lz4
    • This makes compressing data stored into redis much much faster, without it I'ld probably recommend not forcing any compression
Make sure the following is not installed or is disabled;
  • php-xdebug
    • This is for debugging/development only, running this in production is a massive performance penalty. Don't do that.

Not sure if it's by design @Xon but now I see 4 separate Redis blocks in the admin, all showing identical info for each of the above config sections
This is by design as the idea is they will be difference redis instances and not the same one using a different database.
 
Last edited:
I've re-enabled it per above and will see how things go and ensured I have the php items installed. Thanks!
 
Of the items cachable, what should I enable? Sessions? CSS? Registry? for best site performance?
 
Only full-page caching requires explicit cache section setup. And only session-caching requires an enable flag
 
Top Bottom