github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/tools/autoscaling/plugins/strategy/target-value.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Autoscaling Plugins: Target Value'
     4  description: The "target-value" strategy plugin tracks a target metric value.
     5  ---
     6  
     7  # Target Value Strategy Plugin
     8  
     9  The `target-value` strategy plugin performs count calculations in order to
    10  keep the value resulting from the APM query at or around a specified target.
    11  
    12  It accomplishes this by extrapolating the current metric value and used
    13  capacity linearly to determine if a scaling action is required and how many
    14  instances need to be added or removed. More specify, the new scaling value is
    15  calculated as:
    16  
    17  ```
    18  factor = current_metric_value / target
    19  new_count = factor * current_count
    20  ```
    21  
    22  As an example, a policy that tracks memory usage with target defined as `70`
    23  (representing 70% of memory usage) and in a scenario where there are `10`
    24  instances running will generate a scaling action with scaling factor of
    25  `1.1428571429`, which will add `2` new instances when the metric reaches `80`
    26  (80% of memory usage) because:
    27  
    28  ```
    29  factor = 80/70 = 1.1428571429
    30  new_count = 1.1428571429 * 10 ~= 12
    31  ```
    32  
    33  In other words, if with 10 instances the memory usage in 80%, it's expected
    34  that with 12 instances the memory usage will be lower and closer to the target
    35  value of 70%.
    36  
    37  This means that this strategy expects your infrastructure to have the following
    38  characteristics:
    39  
    40  - **inverse relationship** between metric and number of instances, meaning that
    41    adding _more_ instances will cause your metric value to go _down_.
    42  
    43  - **linear response** to infrastructure changes, meaning that a _2x_ increase
    44    in instance count will cut the metric value approximately in _half_.
    45  
    46  ~> **Note:** These properties may not be true for your infrastructure. Make
    47    sure you have a good grasp of your query result dynamic as the number of
    48    instances changes.
    49  
    50  To fine-tune scaling decisions you can adjust the `threshold` configuration.
    51  This value defines a range between `1 ± threshold` where scaling actions with a
    52  scaling factor within this range are ignored. For example, with the default
    53  value of `0.01` only scaling actions with a factor lower than `0.99` and larger
    54  than `1.01` are taken into account.
    55  
    56  With a low `threshold` you are expected to observe more scaling actions with
    57  smaller changes, while a high `threshold` value is expected to generate fewer
    58  scaling actions with bigger changes in count.
    59  
    60  Since `threshold` is compared against the computed scaling factor, and the
    61  factor is based on your expected metric values and specified `target`,
    62  adjusting the `threshold` value can take some time and a few trial and error
    63  attempts.
    64  
    65  ## Agent Configuration Options
    66  
    67  ```hcl
    68  strategy "target-value" {
    69    driver = "target-value"
    70  }
    71  ```
    72  
    73  ## Policy Configuration Options
    74  
    75  ```hcl
    76  check "target-value-check" {
    77    # ...
    78    strategy "target-value" {
    79      target    = 20
    80      threshold = 0.0001
    81    }
    82    # ...
    83  }
    84  ```
    85  
    86  - `target` `(float: <required>)` - Specifies the metric value the Autoscaler
    87    should try to meet.
    88  
    89  - `threshold` `(float: 0.01)` - Specifies how significant a change in the input
    90    metric should be considered. Small threshold values can lead to output
    91    fluctuation.