Class: Octopus::LoadBalancing::RoundRobin

Inherits:
Object
  • Object
show all
Defined in:
lib/octopus/load_balancing/round_robin.rb

Overview

The round-robin load balancing of slaves belonging to the same shard. It is a pool that contains slaves which queries are distributed to.

Instance Method Summary collapse

Constructor Details

#initialize(slaves_list) ⇒ RoundRobin

Returns a new instance of RoundRobin.



6
7
8
9
# File 'lib/octopus/load_balancing/round_robin.rb', line 6

def initialize(slaves_list)
  @slaves_list = slaves_list
  @slave_index = 0
end

Instance Method Details

#nextObject

Returns the next available slave in the pool



12
13
14
# File 'lib/octopus/load_balancing/round_robin.rb', line 12

def next
  @slaves_list[@slave_index = (@slave_index + 1) % @slaves_list.length]
end