cloud performance ai_generated true

Cloud Run request takes 30s+ on first invocation due to large container image

ID: cloud/gcp-cloud-run-cold-start-large-image

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

Cloud Run pulls the container image on cold start. Images >1GB can take 10-30s+ to pull. Google's docs recommend small images but don't quantify the cold start penalty per image size.

generic

Workarounds

  1. 92% success Use multi-stage Docker builds to minimize image size
    FROM golang:1.21 AS builder ... FROM gcr.io/distroless/static ... COPY --from=builder /app /app
  2. 90% success Set min-instances > 0 AND set CPU to 'always allocated' for consistent performance
    gcloud run deploy --min-instances=2 --cpu-boost --no-cpu-throttling
  3. 85% success Use startup CPU boost to reduce cold start latency
    gcloud run deploy --cpu-boost  # doubles CPU during startup for faster init

Dead Ends

Common approaches that don't work:

  1. Set min-instances=1 and assume zero cold starts 78% fail

    min-instances keeps 1 instance warm, but concurrent request spikes still trigger cold starts for additional instances.

  2. Use a health check endpoint to keep instances warm 82% fail

    Cloud Run auto-scales to zero regardless of health checks. There's no built-in keep-alive mechanism.