mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 13:12:45 +08:00
DEV: Log live slots of Sidekiq jobs (#28600)
Introduce a new log line for Sidekiq jobs that consume more than `DISCOURSE_LIVE_SLOTS_SIDEKIQ_LIMIT` live slots. This is useful to track down jobs that may leak memory. This is enabled only when Sidekiq's job instrumenter is enabled (set `DISCOURSE_LOG_SIDEKIQ` to `1`).
This commit is contained in:
parent
c760b30190
commit
95b09dd777
|
@ -136,12 +136,27 @@ module Jobs
|
||||||
@data["@timestamp"] = Time.now
|
@data["@timestamp"] = Time.now
|
||||||
@data["duration"] = current_duration if @data["status"] == "pending"
|
@data["duration"] = current_duration if @data["status"] == "pending"
|
||||||
self.class.raw_log("#{@data.to_json}\n")
|
self.class.raw_log("#{@data.to_json}\n")
|
||||||
|
|
||||||
|
if live_slots_limit > 0 && @data["live_slots_start"].present? &&
|
||||||
|
@data["live_slots_finish"].present?
|
||||||
|
live_slots = @data["live_slots_finish"] - @data["live_slots_start"]
|
||||||
|
|
||||||
|
if live_slots >= live_slots_limit
|
||||||
|
Rails.logger.warn(
|
||||||
|
"Sidekiq Job '#{@data["job_name"]}' allocated #{live_slots} objects in the heap: #{@data.inspect}",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
ENV["DISCOURSE_LOG_SIDEKIQ"] == "1"
|
ENV["DISCOURSE_LOG_SIDEKIQ"] == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def live_slots_limit
|
||||||
|
@live_slots_limit ||= ENV["DISCOURSE_LIVE_SLOTS_SIDEKIQ_LIMIT"].to_i
|
||||||
|
end
|
||||||
|
|
||||||
def self.mutex
|
def self.mutex
|
||||||
@@mutex ||= Mutex.new
|
@@mutex ||= Mutex.new
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user