Automatically scale workloads by resource utilization metrics and cron

Setting cron auto-scaling policy

Introduce how to automatically scale workloads by cron.

  1. Prepare Appfile
  1. name: testapp
  2. services:
  3. express-server:
  4. # this image will be used in both build and deploy steps
  5. image: oamdev/testapp:v1
  6. cmd: ["node", "server.js"]
  7. port: 8080
  8. autoscale:
  9. min: 1
  10. max: 4
  11. cron:
  12. startAt: "14:00"
  13. duration: "2h"
  14. days: "Monday, Thursday"
  15. replicas: 2
  16. timezone: "America/Los_Angeles"
  1. Deploy an application
  1. $ vela up
  2. Parsing vela.yaml ...
  3. Loading templates ...
  4. Rendering configs for service (express-server)...
  5. Writing deploy config to (.vela/deploy.yaml)
  6. Applying deploy configs ...
  7. Checking if app has been deployed...
  8. App has not been deployed, creating a new deployment...
  9. App has been deployed 🚀🚀🚀
  10. Port forward: vela port-forward testapp
  11. SSH: vela exec testapp
  12. Logging: vela logs testapp
  13. App status: vela status testapp
  14. Service status: vela status testapp --svc express-server
  1. Check the replicas and wait for the scaling to take effect

Check the replicas of the application, there is one replica.

  1. $ vela status testapp
  2. About:
  3. Name: testapp
  4. Namespace: default
  5. Created at: 2020-11-05 17:09:02.426632 +0800 CST
  6. Updated at: 2020-11-05 17:09:02.426632 +0800 CST
  7. Services:
  8. - Name: express-server
  9. Type: webservice
  10. HEALTHY Ready: 1/1
  11. Traits:
  12. - autoscale: type: cron replicas(min/max/current): 1/4/1
  13. Last Deployment:
  14. Created at: 2020-11-05 17:09:03 +0800 CST
  15. Updated at: 2020-11-05T17:09:02+08:00

Wait till the time clocks startAt, and check again. The replicas become to two, which is specified as replicas in vela.yaml.

  1. $ vela status testapp
  2. About:
  3. Name: testapp
  4. Namespace: default
  5. Created at: 2020-11-10 10:18:59.498079 +0800 CST
  6. Updated at: 2020-11-10 10:18:59.49808 +0800 CST
  7. Services:
  8. - Name: express-server
  9. Type: webservice
  10. HEALTHY Ready: 2/2
  11. Traits:
  12. - autoscale: type: cron replicas(min/max/current): 1/4/2
  13. Last Deployment:
  14. Created at: 2020-11-10 10:18:59 +0800 CST
  15. Updated at: 2020-11-10T10:18:59+08:00

Wait after the period ends, the replicas will be one eventually.

Setting auto-scaling policy of CPU resource utilization

Introduce how to automatically scale workloads by CPU resource utilization.

  1. Prepare Appfile

Modify vela.yaml as below. We add field services.express-server.cpu and change the auto-scaling policy from cron to cpu utilization by updating filed services.express-server.autoscale.

  1. name: testapp
  2. services:
  3. express-server:
  4. image: oamdev/testapp:v1
  5. cmd: ["node", "server.js"]
  6. port: 8080
  7. cpu: "0.01"
  8. autoscale:
  9. min: 1
  10. max: 5
  11. cpuPercent: 10
  1. Deploy an application
  1. $ vela up
  1. Expose the service entrypoint of the application
  1. $ vela port-forward helloworld 80
  2. Forwarding from 127.0.0.1:80 -> 80
  3. Forwarding from [::1]:80 -> 80
  4. Forward successfully! Opening browser ...
  5. Handling connection for 80
  6. Handling connection for 80
  7. Handling connection for 80
  8. Handling connection for 80

On your macOS, you might need to add sudo ahead of the command.

  1. Monitor the replicas changing

Continue to monitor the replicas changing when the application becomes overloaded. You can use Apache HTTP server benchmarking tool ab to mock many requests to the application.

  1. $ ab -n 10000 -c 200 http://127.0.0.1/
  2. This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/
  5. Benchmarking 127.0.0.1 (be patient)
  6. Completed 1000 requests

The replicas gradually increase from one to four.

  1. $ vela status helloworld --svc frontend
  2. About:
  3. Name: helloworld
  4. Namespace: default
  5. Created at: 2020-11-05 20:07:21.830118 +0800 CST
  6. Updated at: 2020-11-05 20:50:42.664725 +0800 CST
  7. Services:
  8. - Name: frontend
  9. Type: webservice
  10. HEALTHY Ready: 1/1
  11. Traits:
  12. - autoscale: type: cpu cpu-utilization(target/current): 5%/10% replicas(min/max/current): 1/5/2
  13. Last Deployment:
  14. Created at: 2020-11-05 20:07:23 +0800 CST
  15. Updated at: 2020-11-05T20:50:42+08:00
  1. $ vela status helloworld --svc frontend
  2. About:
  3. Name: helloworld
  4. Namespace: default
  5. Created at: 2020-11-05 20:07:21.830118 +0800 CST
  6. Updated at: 2020-11-05 20:50:42.664725 +0800 CST
  7. Services:
  8. - Name: frontend
  9. Type: webservice
  10. HEALTHY Ready: 1/1
  11. Traits:
  12. - autoscale: type: cpu cpu-utilization(target/current): 5%/14% replicas(min/max/current): 1/5/4
  13. Last Deployment:
  14. Created at: 2020-11-05 20:07:23 +0800 CST
  15. Updated at: 2020-11-05T20:50:42+08:00

Stop ab tool, and the replicas will decrease to one eventually.