SOP-003: Configure Autoscaling
DOCUMENT CONTROL
| Field | Value |
|---|---|
| SOP ID | SOP-003 |
| Version | 1.0 |
| Status | Active |
Purpose
Configure Cloud Run autoscaling to optimize cost and performance. Control how your service scales up and down based on traffic demands.
Key Concepts
| Term | Description |
|---|---|
| Concurrency | Max simultaneous requests per instance |
| Min Instances | Always-on instances (0 = scale to zero) |
| Max Instances | Upper scaling limit |
| Cold Start | Time 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 100Step 3: Set Instance Limits
bash
# Configure scaling bounds
gcloud run services update my-service \
--region us-central1 \
--min-instances 1 \
--max-instances 10COST 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| Mode | When CPU Allocated | Best For |
|---|---|---|
| Default | Only during request | Cost optimization |
--no-cpu-throttling | Always on | Background tasks |
--cpu-boost | Extra at startup | Faster cold starts |
Step 5: Set Startup/Shutdown Timeouts
bash
gcloud run services update my-service \
--region us-central1 \
--timeout 300 \
--startup-cpu-boostScaling Strategies
Cost-Optimized (Scale to Zero)
bash
gcloud run services update my-service \
--region us-central1 \
--min-instances 0 \
--max-instances 5 \
--concurrency 80Low-Latency (Always Warm)
bash
gcloud run services update my-service \
--region us-central1 \
--min-instances 2 \
--max-instances 100 \
--concurrency 50 \
--cpu-boostHigh-Throughput (Max Concurrency)
bash
gcloud run services update my-service \
--region us-central1 \
--min-instances 1 \
--max-instances 1000 \
--concurrency 1000 \
--memory 4Gi \
--cpu 4Verification 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
| Instances | Hours/Month | vCPU Cost | Memory Cost (1GB) |
|---|---|---|---|
| 0 (scale to zero) | 0 | $0 | $0 |
| 1 | 730 | ~$47 | ~$5 |
| 2 | 1460 | ~$94 | ~$10 |
| 5 | 3650 | ~$236 | ~$26 |
Prices approximate for us-central1. Use GCP Calculator for exact pricing.