Skip to content

Add ClusterCache for cache migration to Redis Cluster

What does this MR do and why?

This MR introduces the ClusterCache singleton to enable GitLab SaaS to migrate cache workload to a Redis Cluster.

In broad strokes, this MR does:

  1. Introduce ClusterCache because we need to migrate from redis-cluster-cache to redis-cache.
  2. Update Cache to use a MultiStore for migration
  3. Updates redis.yml.example, setting ClusterCache to connect to a Redis Cluster in CI. This mirrors what pre/gstg/gprd will be.
  4. Update lib/gitlab/patch/redis_cache_store.rb to run mget only if the default_store is a standalone Redis. This is to avoid performance regressions when the MultiStore is still reading from the standalone Redis.
  5. Fix specs that tests for strict conditions like number of Redis commands being used (in multistore, we make extra calls)

Note that this MR is only ready after feature-flag gets migrated out of redis-cache.

See gitlab-com/gl-infra/scalability#2016

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Set GDK to run a Redis Cluster (https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/data/announcements/0004_redis_cluster_support.yml)

  1. Update redis.yml
development:
  cluster_cache:
    cluster:
      - redis://localhost:6001
  1. Restart the rails-web
gdk restart rails
  1. Enable use_primary_and_secondary_stores_for_cache and wait for ~1 minute for the in-memory feature flag cache to expire.
Feature.enable(:use_primary_store_as_default_for_cache)

Clicking around on gdk.test:3000 with the performance bar would show ClusterCache with set commands. Running the following line in terminal should show a bunch of keys in the Redis Cluster

for i in 0 1 2; do redis-cli -p 600$i keys '*'; done
Click to see screenshots

Note the mget being used in Cache

Screenshot_2023-06-16_at_11.00.01_AM

  1. Enable use_primary_store_as_default_for_cache and wait for ~1 minute for the in-memory feature flag cache to expire.
Feature.enable(:use_primary_store_as_default_for_cache)

Clicking around on gdk.test:3000 with the performance bar would show ClusterCache forming most of the reads and Cache to be used for writes.

Click to see screenshots

Screenshot_2023-06-16_at_11.01.33_AM

mget are converted to pipelined get

Screenshot_2023-06-16_at_11.01.44_AM

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sylvester Chin

Merge request reports

Loading