Node Auto Scaling

Node auto scaling can be enabled by setting docker:auto-scale:enabled to true orby using tsuru node autoscale rule set to configure a autoscale rule.It will try to add, remove and rebalance docker nodes used by tsuru.

Node scaling algorithms run in clusters of docker nodes, each cluster is basedon the pool the node belongs to.

There are two different scaling algorithms that will be used, depending on howtsuru is configured: count based scaling, and memory based scaling.

Count based scaling

It’s chosen if docker:auto-scale:max-container-count is set to a value > 0 inyour tsuru configuration.

Adding nodes

Having max-container-count value as (max), the number of nodes in clusteras (nodes), and the total number of containers in all cluster’s nodes as(total), we get the number of free slots (free) with:

[free = max * nodes - total]

If (free < 0) then a new node will be added and tsuru will rebalancecontainers using the new node.

Removing nodes

Having docker:auto-scale:scale-down-ratio value (ratio). tsuru will try toremove an existing node if:

[free > max * ratio]

Before removing a node tsuru will move it’s containers to other nodes available inthe cluster.

To avoid entering loops, removing and adding node, tsuru will require (ratio> 1), if this is not true scaling will not run.

Memory based scaling

It’s chosen if docker:auto-scale:max-container-count is not set and yourscheduler is configured to use node’s memory information, by settingdocker:scheduler:total-memory-metadata and docker:scheduler:max-used-memory.

Adding nodes

Having the amount of memory necessary by the plan with the largest memoryrequirement as (maxPlanMemory). A new node will be added if for all nodesthe amount of unreserved memory ((unreserved)) satisfies:

[unreserved < maxPlanMemory]

Removing nodes

Considering the amount of memory necessary by the plan with the largest memoryrequirement as (maxPlanMemory) and _docker:auto-scale:scale-down-ratio_value as (ratio). A node will be removed if its current containers can bedistributed across other nodes in the same pool and at least one node still hasunreserved memory ((unreserved)) satisfying:

[unreserved > maxPlanMemory * ratio]

Rebalancing nodes

Rebalancing containers will be triggered when a new node is added or ifrebalancing would decrease the difference of containers in nodes by a numbergreater than 2, regardless the scaling algorithm.

Also, rebalancing will not run if docker:auto-scale:prevent-rebalance is set totrue.

Auto scale events

Each time tsuru tries to run an auto scale action (add, remove, or rebalance). Itwill create an auto scale event. This event will record the result of the autoscale action and possible errors that occurred during its execution.

You can list auto scale events with tsuru docker-autoscale-list

Running auto scale once

Even if you have not enabled autoscale, you can make tsurutrigger the execution of the auto scale algorithm by running tsuru docker-autoscale-run.

原文: https://docs.tsuru.io/1.6/advanced_topics/node_scaling.html