Class: Aws::Plugins::Retries::ClientRateLimiter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used only in 'adaptive' retry mode

Constant Summary collapse

MIN_CAPACITY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1
MIN_FILL_RATE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

0.5
SMOOTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

0.8
BETA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

How much to scale back after a throttling response

0.7
SCALE_CONSTANT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Controls how aggressively we scale up after being throttled

0.4

Instance Method Summary collapse

Constructor Details

#initializeClientRateLimiter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ClientRateLimiter.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb', line 17

def initialize
  @mutex                = Mutex.new
  @fill_rate            = nil
  @max_capacity         = nil
  @current_capacity     = 0
  @last_timestamp       = nil
  @enabled              = false
  @measured_tx_rate     = 0
  @last_tx_rate_bucket  = Aws::Util.monotonic_seconds
  @request_count        = 0
  @last_max_rate        = 0
  @last_throttle_time   = Aws::Util.monotonic_seconds
  @calculated_rate      = nil
end

Instance Method Details

#token_bucket_acquire(amount, wait_to_fill = true) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb', line 32

def token_bucket_acquire(amount, wait_to_fill = true)
  # Client side throttling is not enabled until we see a
  # throttling error
  return unless @enabled

  @mutex.synchronize do
    token_bucket_refill

    # Next see if we have enough capacity for the requested amount
    while @current_capacity < amount
      raise Aws::Errors::RetryCapacityNotAvailableError unless wait_to_fill
      @mutex.sleep((amount - @current_capacity) / @fill_rate)
      token_bucket_refill
    end
    @current_capacity -= amount
  end
end

#update_sending_rate(is_throttling_error) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb', line 50

def update_sending_rate(is_throttling_error)
  @mutex.synchronize do
    update_measured_rate

    if is_throttling_error
      rate_to_use = if @enabled
                      [@measured_tx_rate, @fill_rate].min
                    else
                      @measured_tx_rate
                    end

      # The fill_rate is from the token bucket
      @last_max_rate = rate_to_use
      calculate_time_window
      @last_throttle_time = Aws::Util.monotonic_seconds
      @calculated_rate = cubic_throttle(rate_to_use)
      enable_token_bucket
    else
      calculate_time_window
      @calculated_rate = cubic_success(Aws::Util.monotonic_seconds)
    end

    new_rate = [@calculated_rate, 2 * @measured_tx_rate].min
    token_bucket_update_rate(new_rate)
  end
end