Skip to content

ConnectionPool of Rails.cache connection on threaded context

Description

Currently on our Sidekiq workers the Rails.cache store which backend is Redis is not using a ConnectionPool for that connection so in threaded context like Sidekiq workers could generate contention.

If you check the Wall Time and CPU Time on methods that just expire a key on redis there are a lot of difference on time.

For example

WallTime -> Repository#expire_tag_count_cache -> duration 95th in average 530ms CPUTime -> Repository#expire_tag_count_cache -> duration 95th in average 0ms

Proposal

Use a connection pool for the Rails.cache store when booting in a Sidekiq worker

Links / references