PERF: Reduce number of EXPIRE calls from CachedCounting (#15958)

Previously we were calling `EXPIRE` every time we incremented a given key. Instead, we can call EXPIRE once when the key is first populated. A LUA script is used to make this as efficient as possible.

Consumers of this Concern use daily keys. Since we're now calling EXPIRE only at the beginning of the day, rather than throughout the day, the expire time has been increased from 3 to 4 days.
This commit is contained in:
David Taylor
2022-02-15 16:55:21 +00:00
committed by GitHub
parent 11c93342dc
commit 94a47d037f
3 changed files with 30 additions and 11 deletions

View File

@@ -29,14 +29,16 @@ describe ApplicationRequest do
inc(:http_total)
inc(:http_total)
Discourse.redis.without_namespace.stubs(:incr).raises(Redis::CommandError.new("READONLY"))
Discourse.redis.without_namespace.stubs(:eval).raises(Redis::CommandError.new("READONLY"))
Discourse.redis.without_namespace.stubs(:evalsha).raises(Redis::CommandError.new("READONLY"))
Discourse.redis.without_namespace.stubs(:set).raises(Redis::CommandError.new("READONLY"))
# flush will be deferred no error raised
inc(:http_total, autoflush: 3)
ApplicationRequest.write_cache!
Discourse.redis.without_namespace.unstub(:incr)
Discourse.redis.without_namespace.unstub(:eval)
Discourse.redis.without_namespace.unstub(:evalsha)
Discourse.redis.without_namespace.unstub(:set)
inc(:http_total, autoflush: 3)