Evaluate redis-sessions workload's Redis Cluster compatibility
With redis-sessions primary cpu on an uptrend, we should start looking at the workload compatibility with Redis Cluster.
Operations used are mostly setex, get, sadd. There is a minor issue of mget and del operations present. This means needing to either (1) convert the mget into pipelines of get, (2) adopt hash-tags in session key (hash tag around user id).
Workload analysis
Folders searched with rg 'Gitlab::Redis::Session' -g '*.rb' -l | sort | grep -v spec
app/models/active_session.rb
config/initializers/session_store.rb
ee/lib/gitlab/auth/otp/session_enforcer.rb
lib/gitlab/anonymous_session.rb
lib/gitlab/redis.rb
| Component | Issues? |
|---|---|
AnonymousSession |
None. All single key and non-cross-slot pipelines |
| Auth::Otp::SessionEnforcer | None. All single key ops |
| ActiveSessions | Yes. (1) cross-slot pipelines. (2) multi-key del and mget
|
Redis store compatibility
Redis::Store works with Redis Cluster as it uses redis-rb v4.8 under the hood. Note that the redis-store v1.9.1 gem which we use in Gitlab is locked to redis-rb v4.x, requiring an upgrade to v1.9.2 if we are using redis-rb v5 by the time of migration.
with
➜ gitlab git:(master) cat config/redis.sessions.yml
---
#development: unix:/Users/sylvesterchin/work/gitlab-development-kit/redis/redis.socket?db=5
development:
cluster:
- redis://localhost:7001
Loading development environment (Rails 6.1.7.2)
[1] pry(main)> store = Gitlab::Redis::Sessions.store(namespace: Gitlab::Redis::Sessions::SESSION_NAMESPACE)
=> #<Redis client v4.8.0 for redis://localhost:7001/0 redis://localhost:7101/0 redis://localhost:7201/0>
[2] pry(main)> store.get('a')
=> nil
[3] pry(main)> store.set('abc', 123)
=> "OK"
[4] pry(main)> store.get('abc')
=> 123
Edited by Sylvester Chin

