Class: HawatelTlb::Mode::Fastest
- Inherits:
-
Object
- Object
- HawatelTlb::Mode::Fastest
- Defined in:
- lib/hawatel_tlb/mode/fastest.rb
Constant Summary collapse
- HISTORY_SIZE =
number of elements stored in history array
3
Instance Method Summary collapse
-
#initialize(group) ⇒ Fastest
constructor
A new instance of Fastest.
-
#node ⇒ Hash
Calculate base on fastest algorithm Algorithm based on history statistics about respond time and ‘online’ states (flapping detection).
-
#refresh(group) ⇒ Object
Refresh group table after delete or add host.
Constructor Details
#initialize(group) ⇒ Fastest
Returns a new instance of Fastest.
7 8 9 10 11 |
# File 'lib/hawatel_tlb/mode/fastest.rb', line 7 def initialize(group) @group = group @history = Array.new @counter = 0 end |
Instance Method Details
#node ⇒ Hash
Calculate base on fastest algorithm Algorithm based on history statistics about respond time and ‘online’ states (flapping detection)
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hawatel_tlb/mode/fastest.rb', line 24 def node # push nodes statistics to history array if @counter < HISTORY_SIZE @history[@counter] = @group.dup @counter += 1 else @counter = 0 @history[@counter] = @group.dup end current_online = Array.new @group.each do |node| current_online.push(node.id) if node.state == 'enable' && node.status[:state] == 'online' end # there is no any available node return false if current_online.empty? # there is only one available node return find_node(current_online[0]) if current_online.size == 1 # there are more that one online nodes nodes_sorted_stats = sort_by_state(average_respond_time(current_online)) # choose only top nodes with equal online state top_nodes_by_state = Array.new top_value = 0 nodes_sorted_stats.each do |node| top_value = node[:online_count] if top_value == 0 if node[:online_count] == top_value top_nodes_by_state.push(node) else break end end # there is only one node with highest online count return find_node(top_nodes_by_state[0][:id]) if top_nodes_by_state.size == 1 # there are more with top top_nodes_by_respond = sort_by_respond(top_nodes_by_state) find_node(top_nodes_by_respond[0][:id]) end |
#refresh(group) ⇒ Object
Refresh group table after delete or add host
16 17 18 |
# File 'lib/hawatel_tlb/mode/fastest.rb', line 16 def refresh(group) @group = group end |