Lab: scale out, then autoscale

Verified lab · 25 min · Module 7, lesson 4 of 530 min left in this module

Module 7 · ScalingLesson 4 of 5

Self-checked for now. Automatic checking arrives with sign-in; until then, tick off each item under Check your work yourself.

Goal: Scale the shop to two spherelets by hand, then let autoscaling take it from one to two under load and back.

You need shop-api Running in your lab environment from lab 6.2.4, room for a second Flex spherelet, and a plan with autoscaling.

Making room, and a shop if you need one

A trial account runs two Flex spherelets in total. Delete the other services in your lab environment (csph services list, then csph services delete <service-id>) so shop-api can use both.

No shop-api? Save this as shop-api.yaml and run csph deploy --file shop-api.yaml:

version: "2"
services:
  - name: shop-api
    type: web-service
    image: quay.io/computesphere/learn-shop-api:1.4.0
    port: 8080
    env_vars:
      REQUIRE_SIGNING_KEY: "false"

Autoscaling comes with the Team plan and above. On another plan, do steps 1 and 2, and read the rest.

  1. Scale out to two

    csph services list
    csph deployments list --service <service-id>
    csph deployments scale <deployment-id> --spheres 2
    

    You should seeThe Spherelets card shows 2, and shop-api is Running again.

  2. See both on the graph

    Open shop-api, then Metrics. Set the time range to Last 15 minutes (or Last 5 minutes) and choose Apply: the 1-hour view may not show the step. It can take 3 to 5 minutes to appear.

    You should seeThe Spherelets chart steps from 1 to 2.

  3. Hand the count to autoscaling

    Open Settings. On the Spherelets card choose Edit and set Spherelets to 1. Turn on Enable Auto-Scaling; set CPU utilization threshold 50, Min spherelets 1, Max spherelets 2. Choose Save, then Save & redeploy.

    You should seeThe card shows Auto scaling Enabled, CPU target 50%, and 1 — 2 under a second Spherelets label.

  4. Put it under load

    Wait for Running with one spherelet, then, with the URL from shop-api's page in the console:

    curl "https://<your-shop-api-url>/burn?seconds=300"
    

    The spherelet that answers keeps one thread busy for five minutes.

    You should seeJSON with burning true and seconds 300.

  5. Watch it scale out

    Watch the CPU and Spherelets charts on the Metrics tab, still on the 15- or 5-minute range.

    Check yourself

    Only one spherelet is burning CPU. Once there are two, why doesn't it add a third?

    You should seeThe CPU chart climbs past half the spherelet's vCPU. About a minute later a second spherelet starts; the chart shows it a few minutes after that.

  6. Watch it scale back

    Keep the Metrics tab open. The count waits for CPU to stay low before it drops.

    You should seeSpherelets returns to 1 about six minutes after the burn ends.

Check your work

  • If this doesn't pass

    If csph scale was refused or the second spherelet never started, another service is using your Flex spherelets. Delete it and scale again.

  • If this doesn't pass

    If Enable Auto-Scaling can't be switched on and says Only 1 Spherelet possible, set Spherelets to 1 first, in the same edit.

  • If this doesn't pass

    Still 1 on the chart? Check the time range is 15 or 5 minutes, and that CPU rose. If the burn ended, call /burn again.