Class: LoadBalancer
- Inherits:
-
Object
- Object
- LoadBalancer
- Includes:
- MonitorMixin
- Defined in:
- lib/logstash/utils/load_balancer.rb
Defined Under Namespace
Classes: HostState
Instance Method Summary collapse
-
#initialize(host_infos, cool_off: 60) ⇒ LoadBalancer
constructor
Creates a new Router with the provided downstream_infos that ignores errors older than the cool_off period.
-
#select { ... } ⇒ Object
Yields the block with a HostState, prioritizing hosts that are less concurrently-used and which have not errored recently.
Constructor Details
#initialize(host_infos, cool_off: 60) ⇒ LoadBalancer
Creates a new Router with the provided downstream_infos that ignores errors older than the cool_off period
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/logstash/utils/load_balancer.rb', line 16 def initialize(host_infos, cool_off: 60) super() # to initialize MonitorMixin fail ArgumentError, "Non-empty `host_infos` hosts required." unless host_infos&.any? fail ArgumentError, "`cool_off` requires integer value." unless cool_off.kind_of?(Integer) @cool_off = cool_off @host_states = host_infos.map do |host_info| HostState.new(host_info) end end |
Instance Method Details
#select { ... } ⇒ Object
Yields the block with a HostState, prioritizing hosts that are less concurrently-used and which have not errored recently.
33 34 35 36 37 38 39 40 41 |
# File 'lib/logstash/utils/load_balancer.rb', line 33 def select selected = synchronize { pick_one.tap(&:increment) } yield selected.uri rescue synchronize { selected.mark_error } raise ensure synchronize { selected.decrement } end |