Commit 88585816 authored by Stan Hu's avatar Stan Hu

Merge branch 'share-redis-cache-connection-pool' into 'master'

Make Rails.cache and Gitlab::Redis::Cache use the same pool

See merge request gitlab-org/gitlab!28074
parents 6cec5a6a bf51dab8
---
title: Make Rails.cache and Gitlab::Redis::Cache share the same Redis connection pool
merge_request: 28074
author:
type: performance
...@@ -258,18 +258,11 @@ module Gitlab ...@@ -258,18 +258,11 @@ module Gitlab
# Use caching across all environments # Use caching across all environments
# Full list of options: # Full list of options:
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new # https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new
caching_config_hash = Gitlab::Redis::Cache.params caching_config_hash = {}
caching_config_hash[:redis] = Gitlab::Redis::Cache.pool
caching_config_hash[:compress] = Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')) caching_config_hash[:compress] = Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1'))
caching_config_hash[:namespace] = Gitlab::Redis::Cache::CACHE_NAMESPACE caching_config_hash[:namespace] = Gitlab::Redis::Cache::CACHE_NAMESPACE
caching_config_hash[:expires_in] = 2.weeks # Cache should not grow forever caching_config_hash[:expires_in] = 2.weeks # Cache should not grow forever
if Gitlab::Runtime.multi_threaded?
caching_config_hash[:pool_size] = Gitlab::Redis::Cache.pool_size
caching_config_hash[:pool_timeout] = 1
end
# Overrides RedisCacheStore's default value of 0
# This makes the default value the same with Gitlab::Redis::Cache
caching_config_hash[:reconnect_attempts] ||= ::Redis::Client::DEFAULTS[:reconnect_attempts]
config.cache_store = :redis_cache_store, caching_config_hash config.cache_store = :redis_cache_store, caching_config_hash
......
...@@ -15,8 +15,11 @@ module Gitlab ...@@ -15,8 +15,11 @@ module Gitlab
delegate :params, :url, to: :new delegate :params, :url, to: :new
def with def with
pool.with { |redis| yield redis }
end
def pool
@pool ||= ConnectionPool.new(size: pool_size) { ::Redis.new(params) } @pool ||= ConnectionPool.new(size: pool_size) { ::Redis.new(params) }
@pool.with { |redis| yield redis }
end end
def pool_size def pool_size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment