Class: SidekiqAutoscale::Strategies::DelayScaling
- Inherits:
-
BaseScaling
- Object
- BaseScaling
- SidekiqAutoscale::Strategies::DelayScaling
- Defined in:
- lib/sidekiq_autoscale/strategies/delay_scaling.rb
Constant Summary collapse
- SAMPLE_RANGE =
60
- DELAY_LOG_KEY =
"sidekiq_autoscaling:delay_log"
- DELAY_AVERAGE_CACHE_KEY =
"sidekiq_autoscaling:delay_average"
- LOG_TAG =
"[SIDEKIQ_SCALE][DELAY_SCALING]"
Instance Method Summary collapse
Instance Method Details
#log_job(job) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sidekiq_autoscale/strategies/delay_scaling.rb', line 11 def log_job(job) = Time.current.to_f # Gotta do it this way so that each entry is guaranteed to be unique zset_payload = {delay: ( - job["enqueued_at"]), jid: job["jid"]}.to_json # Redis zadd runs in O(log(N)) time, so this should be threaded to avoid blocking # Also, it should be connection-pooled, but I can't remember if we're using # redis connection pooling anywhere Thread.new { SidekiqAutoscale.redis_client.zadd(DELAY_LOG_KEY, , zset_payload) } end |
#scaling_direction(_job) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/sidekiq_autoscale/strategies/delay_scaling.rb', line 29 def scaling_direction(_job) return -1 if workload_too_low? return 1 if workload_too_high? 0 end |
#workload_change_needed?(_job) ⇒ Boolean
25 26 27 |
# File 'lib/sidekiq_autoscale/strategies/delay_scaling.rb', line 25 def workload_change_needed?(_job) workload_too_high? || workload_too_low? end |