Skip to content

SOP-003: Configure Autoscaling

DOCUMENT CONTROL

FieldValue
SOP IDSOP-003
Version1.0
StatusActive

Purpose

Configure Cloud Run autoscaling to optimize cost and performance. Control how your service scales up and down based on traffic demands.

Key Concepts

TermDescription
ConcurrencyMax simultaneous requests per instance
Min InstancesAlways-on instances (0 = scale to zero)
Max InstancesUpper scaling limit
Cold StartTime to start new instance from zero

Flowchart

                 ┌──────────────┐
                 │   Request    │
                 │   Arrives    │
                 └──────┬───────┘

         ┌──────────────┴──────────────┐
         │                             │
         ▼                             ▼
┌─────────────────┐         ┌─────────────────┐
│ Existing Inst.  │         │  No Available   │
│   Available?    │         │    Instance     │
└────────┬────────┘         └────────┬────────┘
         │ Yes                       │
         ▼                           ▼
┌─────────────────┐         ┌─────────────────┐
│ Route to Inst.  │         │  Cold Start     │
│ (if < concur.)  │         │  New Instance   │
└─────────────────┘         └────────┬────────┘


                            ┌─────────────────┐
                            │ Route Request   │
                            └─────────────────┘

Procedure

Step 1: Analyze Current Traffic Patterns

bash
# View current metrics
gcloud run services describe my-service \
  --region us-central1 \
  --format 'yaml(status.traffic,spec.template.spec.containerConcurrency)'

Step 2: Configure Concurrency

CONCURRENCY GUIDELINES

  • CPU-bound tasks: Lower concurrency (1-10)
  • I/O-bound tasks: Higher concurrency (50-100)
  • Default: 80 concurrent requests
bash
# Set concurrency limit
gcloud run services update my-service \
  --region us-central1 \
  --concurrency 100

Step 3: Set Instance Limits

bash
# Configure scaling bounds
gcloud run services update my-service \
  --region us-central1 \
  --min-instances 1 \
  --max-instances 10

COST IMPLICATIONS

Setting --min-instances > 0 means you'll always pay for at least that many instances, even with no traffic.

Step 4: Configure CPU Allocation

bash
# Always-on CPU (recommended for latency-sensitive apps)
gcloud run services update my-service \
  --region us-central1 \
  --cpu-boost \
  --no-cpu-throttling
ModeWhen CPU AllocatedBest For
DefaultOnly during requestCost optimization
--no-cpu-throttlingAlways onBackground tasks
--cpu-boostExtra at startupFaster cold starts

Step 5: Set Startup/Shutdown Timeouts

bash
gcloud run services update my-service \
  --region us-central1 \
  --timeout 300 \
  --startup-cpu-boost

Scaling Strategies

Cost-Optimized (Scale to Zero)

bash
gcloud run services update my-service \
  --region us-central1 \
  --min-instances 0 \
  --max-instances 5 \
  --concurrency 80

Low-Latency (Always Warm)

bash
gcloud run services update my-service \
  --region us-central1 \
  --min-instances 2 \
  --max-instances 100 \
  --concurrency 50 \
  --cpu-boost

High-Throughput (Max Concurrency)

bash
gcloud run services update my-service \
  --region us-central1 \
  --min-instances 1 \
  --max-instances 1000 \
  --concurrency 1000 \
  --memory 4Gi \
  --cpu 4

Verification Checklist

  • [ ] Concurrency matches application capability
  • [ ] Min instances set based on latency requirements
  • [ ] Max instances within budget constraints
  • [ ] CPU allocation mode appropriate for workload
  • [ ] Monitored in Cloud Monitoring dashboard

Monitoring Autoscaling

bash
# View instance count over time
gcloud monitoring dashboards list

# Check current instance count
gcloud run services describe my-service \
  --region us-central1 \
  --format 'value(status.conditions)'

Cost Calculator

InstancesHours/MonthvCPU CostMemory Cost (1GB)
0 (scale to zero)0$0$0
1730~$47~$5
21460~$94~$10
53650~$236~$26

Prices approximate for us-central1. Use GCP Calculator for exact pricing.