Automatically increase or reduce nodes in one Spanner instance
Home
·
Poller function
·
Scaler function
·
Forwarder function
·
Terraform configuration
The Scaler function receives a message from the Poller function that includes the utilization metrics for a single Spanner instance. It compares the metric values with the recommended thresholds, plus or minus an allowed margin. The Scaler function determines if the instance should be scaled, the number of nodes it should be scaled to and adjusts the number of nodes in the Spanner instance accordingly.
The Scaler function supports three scaling methods out of the box:
-
STEPWISE: This is the default method used by the Scaler. It suggests adding or removing nodes using fixed step amount defined by the parameter
stepSize
. In an overload situation, when the instance High Priority CPU utilization is over 90%, the Scaler uses theoverloadStepSize
parameter instead. -
LINEAR: This method suggests adding or removing nodes calculated with a simple linear cross multiplication. This way, the new number of nodes is directly proportional to the current resource utilization.
-
DIRECT: This method suggests scaling to the number of nodes specified by the
maxNodes
parameter. It does NOT take in account the current utilization metrics. It is useful to scale an instance in preparation for a batch job and and to scale it back after the job is finished.
You can define you own scaling method by creating a new file in the
scaling-methods
directory. Your file must export a calculateNumNodes
function that receives an object and returns an integer. The input object
contains the message payload received from the Poller function. See
more information about the message payload.
exports.calculateNumNodes = (spanner) => {
console.log('---- MY_METHOD node suggestions for ' + spanner.projectId + "/" + spanner.instanceId + '----');
//...
return 42;
}
As opposed to the Poller function, the Scaler function does not need any user configuration. The parameters that the Scaler receives are a subset of the configuration parameters used by the Poller function.
The messages sent to the Scaler function from the Poller function include this subset, the Spanner instance metrics, the current number of nodes and a flag to indicate if the Spanner instance is regional or multi-regional.
The following is an example:
{
"minNodes":1,
"maxNodes":3,
"stepSize":1,
"overloadStepSize":5,
"scaleOutCoolingMinutes":5,
"scaleInCoolingMinutes":30,
"scalingMethod":"STEPWISE",
"projectId":"my-spanner-project",
"instanceId":"spanner1",
"scalerPubSubTopic":"projects/my-spanner-project/topics/spanner-scaling",
"metrics":[
{
"name":"high_priority_cpu",
"threshold":65,
"value":95
},
{
"name":"rolling_24_hr",
"threshold":90,
"value":80
},
{
"name":"storage",
"threshold":75,
"value":80,
"margin":10
}
],
"currentNodes":1,
"regional":true
}