Commit 8c717504 authored by Stan Hu's avatar Stan Hu

Enable Redis cache key compression

We have a number of keys that are over 1 MB that would be compressed
significantly (over 90%) if this feature were enabled. We had this
disabled by default to ensure backwards compatibility with the previous
Redis store.

We should enable it now because compression significantly reduces the
pressure on the Redis server. Every time a large payload is stored in
Redis, Redis may need to evict many small keys to make room.

This adds a little more CPU overhead on the application workers, which
is why we have an environment variable
(`ENABLE_REDIS_CACHE_COMPRESSION`) to turn if off it it becomes a
problem.

Behind the scenes, Rails implements this by serializing a `compressed`
variable with the `ActiveSupport::Cache::Entry` if the payload size
exceeds the compression threshold (4K by default). When the entry is
deserialized from Redis, if the `compressed` boolean is set, the value
will be decompressed. Thus even in a mixed-deployment where this setting
is not on by default, Rails will be able to decode compressed values
just fine.

Closes https://gitlab.com/gitlab-org/gitlab/issues/198586
parent 3c1e19ba
---
title: Enable Redis cache key compression
merge_request: 27254
author:
type: performance
......@@ -258,7 +258,7 @@ module Gitlab
# Full list of options:
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new
caching_config_hash = Gitlab::Redis::Cache.params
caching_config_hash[:compress] = false
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[:expires_in] = 2.weeks # Cache should not grow forever
if Gitlab::Runtime.multi_threaded?
......
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