infojolt
infojolt

Reputation: 5418

Why is read replica on Elasticache Redis instance not showing handling any read requests?

I have an AWS Elasticache Redis instance with 2 nodes - primary and a read replica. I'm connecting to the instance using StackExchange.Redis.

The databases value passed to the constructor is a comma separated string containing both the primary endpoint and the reader endpoint.

public class RedisCacheConnectionFactory : IRedisCacheConnectionFactory
{
    private readonly Lazy<ConnectionMultiplexer> _connector;

    public RedisCacheConnectionFactory(string databases)
    {
        var options = ConfigurationOptions.Parse(databases);
        options.AbortOnConnectFail = false;
        options.SyncTimeout = 1000;
        this._connector = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(options));
    }

    public ConnectionMultiplexer Connection() => this._connector.Value;
}

It looks like no read requests are going to the read replica and they are all hitting the primary instance.

Cloudwatch logs showing no reads to read replica

I was under the impression that read replicas would help share the load of read requests to increase throughput. Why are no read requests showing against the read replica?

Upvotes: 1

Views: 1780

Answers (1)

Dave Black
Dave Black

Reputation: 8049

  1. You'll need to specify both the Master and Replica endpoints to the Redis configuration on your redis client.
  2. There is a flag for Redis commands that allows you to control replica usage. The default implementation prefers Master. You'd need to explicitly specify the optional CommandFlags param to either CommandFlags.PreferSlave or CommandFlags.PreferReplica (looks like they are both set to the same value).

See here: https://github.com/StackExchange/StackExchange.Redis/issues/1363#issuecomment-590592408

and

https://github.com/StackExchange/StackExchange.Redis/blob/8612fb8a9278822c87d5476819325a7438e596ca/src/StackExchange.Redis/Enums/CommandFlags.cs#L53

Upvotes: 0

Related Questions