Dead simple autoscaling for Marathon.
618
Dead simple autoscaling for Marathon.
Users can configure each application with a unique set of triggers and thresholds for scaling when deploying. stretch includes a number of built-in triggers (CPU, RAM, HTTP) that are ready to use, but if required it is possible to add completely custom triggers.
WARNING: stretch is currently pre-alpha quality, use in production at your own risk.
#!/usr/bin/env pseudocode
while True:
for app in marathon.list_applications():
if not app.configured:
continue
result = app.check_triggers()
if result == SCALE_UP:
app.scale_up()
elif result == SCALE_DOWN:
app.scale_down()
sleep(30)
stretch fetches a list of all deployed applications using the Marathon API. The list of applications is parsed and those without valid autoscaling configurations are discarded.
For each configured application, stretch checks the configured triggers, aggregating the results of all triggers to make a single decision or whether to scale an application up/down or to do nothing.
stretch repeats this process (with a configurable delay between runs) until stopped.
Triggers are fundamental to how stretch operates. Triggers are configured on a per application basis and return a scale-up/scale-down/do-nothing response. Triggers define the configuration values that they require, each type can require extra values as needed.
stretch will scale an application up if any one of its triggers returns a SCALE_UP response, but will only scale an application down if all triggers return SCALE_DOWN responses.
Built-in triggers include:
All current built-in triggers can be configured with upper/lower thresholds which control when scaling is triggered. Custom triggers do not have to use the threshold mechanic.
TODO/potential triggers
Full configuration details for built in triggers follows below.
An application defines its own autoscaling configuration using Marathon labels at deploy time. If the required labels are not defined the application will be ignored and not considered for scaling.
When configuring triggers, a common prefix is used to group all configuration for each single trigger. Prefixes should take the form r'^SCALING_TRIGGER_[0-9]+'. The numbers ([0-9]+) used are irrelevant, but should be unique for each specific trigger being configured per application, e.g.:
"labels": {
...
"SCALING_TRIGGER_00_TYPE": "mem",
"SCALING_TRIGGER_00_LOWER_THRESHOLD": "20",
"SCALING_TRIGGER_00_UPPER_THRESHOLD": "80",
"SCALING_TRIGGER_01_TYPE": "http",
"SCALING_TRIGGER_01_URL": "/metrics/requests-per-second",
"SCALING_TRIGGER_01_LOWER_THRESHOLD": "250",
"SCALING_TRIGGER_01_UPPER_THRESHOLD": "1000",
...
}
For all sections below, the variable $(TRIGGER_PREFIX) is used to represent the per-trigger unique prefix.
(cpu)Trigger scaling based on the total CPU time (system + user), averaged across all running instances.
SCALE_DOWN result.SCALE_UP result.(mem)Trigger scaling based on % total memory usage, averaged across all running instances.
SCALE_DOWN result.SCALE_UP result.(http)Retrieve a single float value from a HTTP endpoint on each running instance. Trigger scaling based on the average of all values received from the instances.
/status/jobs-in-queue?queue=batch, including the host or domain will result in a misconfiguration error for the triger. The numbers returned from all instances will be averaged before use.SCALE_DOWN result.SCALE_UP result.(http_single)Retrieve a single float value from one HTTP endpoint. Trigger scaling based on the value received.
http://www.example.com/metrics/requests-count?per=second. Failure to use an absolute URL will result in a misconfiguration error for the triger.SCALE_DOWN result.SCALE_UP result.stretch is a work in progress, and there is a lot of work remaining to be done. A non-exhaustive list might look something like:
If there are specific issues you'd like addressed or prioritised, please don't hesitate to file an issue.
Content type
Image
Digest
Size
15.4 MB
Last updated
over 8 years ago
docker pull paddycarey/stretch