Class: ScoutApm::SlowJobPolicy
- Inherits:
-
Object
- Object
- ScoutApm::SlowJobPolicy
- Defined in:
- lib/scout_apm/slow_job_policy.rb
Constant Summary collapse
- DEFAULT_HISTOGRAM_SIZE =
50
- QUANTILE =
95
Instance Method Summary collapse
-
#initialize(histogram_size = DEFAULT_HISTOGRAM_SIZE) ⇒ SlowJobPolicy
constructor
A new instance of SlowJobPolicy.
-
#slow?(worker, total_time) ⇒ Boolean
worker: just the worker class name.
Constructor Details
#initialize(histogram_size = DEFAULT_HISTOGRAM_SIZE) ⇒ SlowJobPolicy
Returns a new instance of SlowJobPolicy.
15 16 17 |
# File 'lib/scout_apm/slow_job_policy.rb', line 15 def initialize(histogram_size = DEFAULT_HISTOGRAM_SIZE) @histograms = Hash.new { |h, k| h[k] = NumericHistogram.new(histogram_size) } end |
Instance Method Details
#slow?(worker, total_time) ⇒ Boolean
worker: just the worker class name. “PasswordResetJob” or similar total_time: runtime of the job in seconds returns true if this request should be stored in higher trace detail, false otherwise
22 23 24 25 26 27 |
# File 'lib/scout_apm/slow_job_policy.rb', line 22 def slow?(worker, total_time) @histograms[worker].add(total_time) return false if @histograms[worker].total == 1 # First call is never slow total_time >= @histograms[worker].quantile(QUANTILE) end |