Module: Sbmt::Outbox::V2::PollThrottler
- Defined in:
- lib/sbmt/outbox/v2/poll_throttler.rb,
lib/sbmt/outbox/v2/poll_throttler/base.rb,
lib/sbmt/outbox/v2/poll_throttler/noop.rb,
lib/sbmt/outbox/v2/poll_throttler/composite.rb,
lib/sbmt/outbox/v2/poll_throttler/paused_box.rb,
lib/sbmt/outbox/v2/poll_throttler/fixed_delay.rb,
lib/sbmt/outbox/v2/poll_throttler/rate_limited.rb,
lib/sbmt/outbox/v2/poll_throttler/redis_queue_size.rb,
lib/sbmt/outbox/v2/poll_throttler/redis_queue_time_lag.rb
Defined Under Namespace
Classes: Base, Composite, FixedDelay, Noop, PausedBox, RateLimited, RedisQueueSize, RedisQueueTimeLag
Constant Summary collapse
- POLL_TACTICS =
%w[noop default low-priority aggressive]
Class Method Summary collapse
Class Method Details
.build(tactic, redis, poller_config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sbmt/outbox/v2/poll_throttler.rb', line 18 def self.build(tactic, redis, poller_config) raise "WARN: invalid poller poll tactic provided: #{tactic}, available options: #{POLL_TACTICS}" unless POLL_TACTICS.include?(tactic) # no-op, for testing purposes return Noop.new if tactic == "noop" if tactic == "default" # composite of RateLimited & RedisQueueSize (upper bound only) # optimal polling performance for most cases Composite.new(throttlers: [ PausedBox.new, RedisQueueSize.new(redis: redis, max_size: poller_config.max_queue_size, delay: poller_config.queue_delay), RateLimited.new(limit: poller_config.rate_limit, interval: poller_config.rate_interval) ]) elsif tactic == "low-priority" # composite of RateLimited & RedisQueueSize (with lower & upper bounds) & RedisQueueTimeLag, # delays polling depending on min job queue size threshold # and also by min redis queue oldest item lag # optimal polling performance for low-intensity data flow Composite.new(throttlers: [ PausedBox.new, RedisQueueSize.new(redis: redis, min_size: poller_config.min_queue_size, max_size: poller_config.max_queue_size, delay: poller_config.queue_delay), RedisQueueTimeLag.new(redis: redis, min_lag: poller_config.min_queue_timelag, delay: poller_config.queue_delay), RateLimited.new(limit: poller_config.rate_limit, interval: poller_config.rate_interval) ]) elsif tactic == "aggressive" # throttles only by max job queue size, max polling performance # optimal polling performance for high-intensity data flow Composite.new(throttlers: [ PausedBox.new, RedisQueueSize.new(redis: redis, max_size: poller_config.max_queue_size, delay: poller_config.queue_delay) ]) end end |