Class: Gitlab::SidekiqDaemon::MemoryKiller

Inherits:
Daemon
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/sidekiq_daemon/memory_killer.rb

Constant Summary collapse

MAX_MEMORY_KB =

Today 64-bit CPU support max 256T memory. It is big enough.

256 * 1024 * 1024 * 1024
SOFT_LIMIT_RSS_KB =

RSS below `soft_limit_rss` is considered safe

ENV.fetch('SIDEKIQ_MEMORY_KILLER_MAX_RSS', 2000000).to_i
HARD_LIMIT_RSS_KB =

RSS above `hard_limit_rss` will be stopped

ENV.fetch('SIDEKIQ_MEMORY_KILLER_HARD_LIMIT_RSS', MAX_MEMORY_KB).to_i
GRACE_BALLOON_SECONDS =

RSS in range (soft_limit_rss, hard_limit_rss) is allowed for GRACE_BALLOON_SECONDS

ENV.fetch('SIDEKIQ_MEMORY_KILLER_GRACE_TIME', 15 * 60).to_i
CHECK_INTERVAL_SECONDS =

Check RSS every CHECK_INTERVAL_SECONDS, minimum 2 seconds

[ENV.fetch('SIDEKIQ_MEMORY_KILLER_CHECK_INTERVAL', 3).to_i, 2].max
SHUTDOWN_TIMEOUT_SECONDS =

Give Sidekiq up to 30 seconds to allow existing jobs to finish after exceeding the limit

ENV.fetch('SIDEKIQ_MEMORY_KILLER_SHUTDOWN_WAIT', 30).to_i
DEFAULT_MAX_MEMORY_GROWTH_KB =

Developer/admin should always set `memory_killer_max_memory_growth_kb` explicitly In case not set, default to 300M. This is for extra-safe.

300_000
PHASE =

Phases of memory killer

{
  running: 1,
  above_soft_limit: 2,
  stop_fetching_new_jobs: 3,
  shutting_down: 4,
  killing_sidekiq: 5
}.freeze

Instance Attribute Summary

Attributes inherited from Daemon

#thread

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from Daemon

initialize_instance, instance, #start, #stop, #thread?, #thread_name

Constructor Details

#initializeMemoryKiller

Returns a new instance of MemoryKiller.


33
34
35
36
37
38
# File 'lib/gitlab/sidekiq_daemon/memory_killer.rb', line 33

def initialize
  super

  @enabled = true
  @metrics = init_metrics
end