diff options
author | Imre Farkas <ifarkas@gitlab.com> | 2019-07-17 14:07:26 +0300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-07-17 14:07:26 +0300 |
commit | f463a2d95b657cf9470053eeb3d12d236e3febb4 (patch) | |
tree | 08a1a03b62ec7bdf959c946815bb4c63023c63fe /app | |
parent | 4f95a8d7f6612e8df138bd831db7f689a01ef9ca (diff) |
Do Redis lookup in batches in ActiveSession.sessions_from_ids
By doing smaller mget calls to Redis, it can better schedule the
workload. Currently a single mget with a lot of keys can keep Redis busy
for long, while nothing in its queue gets processed.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/active_session.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/app/models/active_session.rb b/app/models/active_session.rb index f355b02c428..345767179eb 100644 --- a/app/models/active_session.rb +++ b/app/models/active_session.rb @@ -3,6 +3,8 @@ class ActiveSession include ActiveModel::Model + SESSION_BATCH_SIZE = 200 + attr_accessor :created_at, :updated_at, :session_id, :ip_address, :browser, :os, :device_name, :device_type, @@ -106,10 +108,12 @@ class ActiveSession Gitlab::Redis::SharedState.with do |redis| session_keys = session_ids.map { |session_id| "#{Gitlab::Redis::SharedState::SESSION_NAMESPACE}:#{session_id}" } - redis.mget(session_keys).compact.map do |raw_session| - # rubocop:disable Security/MarshalLoad - Marshal.load(raw_session) - # rubocop:enable Security/MarshalLoad + session_keys.each_slice(SESSION_BATCH_SIZE).flat_map do |session_keys_batch| + redis.mget(session_keys_batch).compact.map do |raw_session| + # rubocop:disable Security/MarshalLoad + Marshal.load(raw_session) + # rubocop:enable Security/MarshalLoad + end end end end |