From e175c643be04d851c0ee3b454ac9c3128d0f5e3c Mon Sep 17 00:00:00 2001 From: Junaid Ahmed Date: Tue, 16 Jun 2026 23:36:42 +0100 Subject: [PATCH] perf(personal-site-2026): tighten startup probe to cut cold start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cloud-run module's startup probe (initial_delay 5s, period 10s) held every scale-from-zero instance "not ready" for a fixed ~5s, even though the compiled Deno binary serves in ~1.7s — pinning cold starts at ~5.1s. Expose the probe schedule as a module variable defaulting to the existing 5/10/3/3 values (no change for any other caller), and override it for personal-site-2026 to 0/1/10/1 so a ready instance is detected in ~1s. --- terraform/apps/personal-site-2026.tf | 11 +++++++++++ terraform/modules/cloud-run/main.tf | 8 ++++---- terraform/modules/cloud-run/variables.tf | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/terraform/apps/personal-site-2026.tf b/terraform/apps/personal-site-2026.tf index 086552a..8c9d9b1 100644 --- a/terraform/apps/personal-site-2026.tf +++ b/terraform/apps/personal-site-2026.tf @@ -46,6 +46,17 @@ module "personal_site_cloud_run" { max_instances = 1 health_path = "/" + # The compiled Deno binary is serving in ~1.7s, yet the module's default probe + # (initial_delay 5s, period 10s) holds the instance "not ready" for a fixed 5s, + # pinning every scale-from-zero request at ~5.1s. Probe from t=0 every 1s so a + # ready instance is picked up in ~1s; failure_threshold keeps a 10s boot budget. + startup_probe = { + initial_delay_seconds = 0 + period_seconds = 1 + failure_threshold = 10 + timeout_seconds = 1 + } + depends_on = [module.personal_site_identity] } diff --git a/terraform/modules/cloud-run/main.tf b/terraform/modules/cloud-run/main.tf index b446d0c..88053ac 100644 --- a/terraform/modules/cloud-run/main.tf +++ b/terraform/modules/cloud-run/main.tf @@ -42,10 +42,10 @@ resource "google_cloud_run_v2_service" "default" { http_get { path = var.health_path } - initial_delay_seconds = 5 - period_seconds = 10 - failure_threshold = 3 - timeout_seconds = 3 + initial_delay_seconds = var.startup_probe.initial_delay_seconds + period_seconds = var.startup_probe.period_seconds + failure_threshold = var.startup_probe.failure_threshold + timeout_seconds = var.startup_probe.timeout_seconds } liveness_probe { diff --git a/terraform/modules/cloud-run/variables.tf b/terraform/modules/cloud-run/variables.tf index fdb99fc..8ad621d 100644 --- a/terraform/modules/cloud-run/variables.tf +++ b/terraform/modules/cloud-run/variables.tf @@ -55,6 +55,22 @@ variable "health_path" { default = "/api/health" } +variable "startup_probe" { + description = "Startup-probe schedule. Defaults preserve the original behaviour; override per-app to tune cold-start readiness." + type = object({ + initial_delay_seconds = number + period_seconds = number + failure_threshold = number + timeout_seconds = number + }) + default = { + initial_delay_seconds = 5 + period_seconds = 10 + failure_threshold = 3 + timeout_seconds = 3 + } +} + variable "allow_unauthenticated" { description = "Allow public access to the service" type = bool