debian-mirror-gitlab/lib/gitlab/cluster/puma_worker_killer_initializer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Gitlab
module Cluster
class PumaWorkerKillerInitializer
2019-12-26 22:10:19 +05:30
def self.start(
puma_options,
2022-08-13 15:12:31 +05:30
puma_per_worker_max_memory_mb: 1200,
puma_master_max_memory_mb: 950,
additional_puma_dev_max_memory_mb: 200)
2023-01-13 00:05:48 +05:30
# We are replacing PWK with Watchdog by using backward compatible RssMemoryLimit monitor by default.
# https://gitlab.com/groups/gitlab-org/-/epics/9119
return if Gitlab::Utils.to_boolean(ENV.fetch('GITLAB_MEMORY_WATCHDOG_ENABLED', true))
2018-12-13 13:39:08 +05:30
require 'puma_worker_killer'
PumaWorkerKiller.config do |config|
worker_count = puma_options[:workers] || 1
2021-09-04 01:27:46 +05:30
# The Puma Worker Killer checks the total memory used by the cluster,
# i.e. both primary and worker processes.
2018-12-13 13:39:08 +05:30
# https://github.com/schneems/puma_worker_killer/blob/v0.1.0/lib/puma_worker_killer/puma_memory.rb#L57
2019-12-26 22:10:19 +05:30
#
# Additional memory is added when running in `development`
config.ram = puma_master_max_memory_mb +
(worker_count * puma_per_worker_max_memory_mb) +
(Rails.env.development? ? (1 + worker_count) * additional_puma_dev_max_memory_mb : 0)
2018-12-13 13:39:08 +05:30
config.frequency = 20 # seconds
# We just want to limit to a fixed maximum, unrelated to the total amount
# of available RAM.
config.percent_usage = 0.98
2019-12-21 20:55:43 +05:30
# Ideally we'll never hit the maximum amount of memory. Restart the workers
# regularly rather than rely on OOM behavior for periodic restarting.
config.rolling_restart_frequency = 43200 # 12 hours in seconds.
2019-09-04 21:01:54 +05:30
2021-03-11 19:13:27 +05:30
# Spread the rolling restarts out over 1 hour to avoid too many simultaneous
# process startups.
config.rolling_restart_splay_seconds = 0.0..3600.0 # 0 to 1 hour in seconds.
2019-09-04 21:01:54 +05:30
observer = Gitlab::Cluster::PumaWorkerKillerObserver.new
config.pre_term = observer.callback
2018-12-13 13:39:08 +05:30
end
PumaWorkerKiller.start
end
end
end
end