Module: Lhm::Throttler::BackoffReduction

Included in:
ReplicaLag, ThreadsRunning, Time
Defined in:
lib/lhm/throttler/backoff_reduction.rb

Constant Summary collapse

DEFAULT_BACKOFF_REDUCTION_FACTOR =
0.2
MIN_STRIDE_SIZE =
1

Instance Method Summary collapse

Instance Method Details

#backoff_strideObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lhm/throttler/backoff_reduction.rb', line 28

def backoff_stride
  new_stride = (@stride * (1 - @backoff_reduction_factor)).to_i

  if new_stride == @stride
    raise RuntimeError, "Cannot backoff any further"
  end

  if new_stride < @min_stride_size
    raise RuntimeError, "Cannot reduce stride below #{@min_stride_size}"
  end
  @stride = new_stride
end

#initialize(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lhm/throttler/backoff_reduction.rb', line 7

def initialize(options = {})
  @backoff_reduction_factor = options[:backoff_reduction_factor] || DEFAULT_BACKOFF_REDUCTION_FACTOR
  @min_stride_size = options[:min_stride_size] || MIN_STRIDE_SIZE

  if @backoff_reduction_factor >= 1 || @backoff_reduction_factor <= 0
    raise ArgumentError, 'backoff_reduction_factor must be between greater than 0, and less than 1'
  end

  if @min_stride_size < 1
    raise ArgumentError, 'min_stride_size must be an integer greater than 0'
  end

  if !@min_stride_size.is_a?(Integer)
    raise ArgumentError, 'min_stride_size must be an integer'
  end

  if @min_stride_size > @stride
    raise ArgumentError, 'min_stride_size must be less than or equal to stride'
  end
end