From a1a1965d2bf9b39447fd9f8ac5322451a425cdc4 Mon Sep 17 00:00:00 2001 From: Yann MAHE Date: Thu, 4 Dec 2025 09:50:31 -0500 Subject: [PATCH 1/4] timing --- niteshift-setup.sh | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/niteshift-setup.sh b/niteshift-setup.sh index 61522c93..ced6bfde 100755 --- a/niteshift-setup.sh +++ b/niteshift-setup.sh @@ -17,6 +17,13 @@ log_error() { echo "ERROR: $*" >&2 } +# Track high-level phase durations using bash's SECONDS counter. +# SECONDS starts at 0 for each shell, so this gives us simple per-run timings +# without relying on external time utilities inside the sandbox image. +SCRIPT_START_SECONDS=${SECONDS:-0} +PNPM_INSTALL_DURATION_S=0 +DEV_SERVER_TO_PREVIEW_DURATION_S=0 + DB_SETUP_SENTINEL="${DB_SETUP_SENTINEL:-$(pwd)/.niteshift-db-setup-complete}" PREBAKE_SYNC_SENTINEL="${PREBAKE_SYNC_SENTINEL:-$(pwd)/.niteshift-prebake-sync-complete}" @@ -78,6 +85,7 @@ fi log "✓ pnpm is available" # 4. Install dependencies +PNPM_INSTALL_START_SECONDS=$SECONDS if [[ "$USE_PREBAKED_SETUP" -eq 0 ]]; then log "Installing dependencies with pnpm..." if ! pnpm install --package-import-method=copy --frozen-lockfile; then @@ -100,6 +108,8 @@ else log "✓ Dependencies installed via fallback" fi fi +PNPM_INSTALL_DURATION_S=$((SECONDS - PNPM_INSTALL_START_SECONDS)) +log "pnpm install phase duration: ${PNPM_INSTALL_DURATION_S}s" # 5. Build only what's needed for dev (skip production Next.js build) # For dev mode we need: @@ -193,6 +203,7 @@ else fi # 6. Start the dev server in the background +DEV_PHASE_START_SECONDS=$SECONDS log "Starting development server on port 3001 (with hot reload)..." # Log dev server output to NITESHIFT_LOG_FILE (or stdout if not set) pnpm run dev >> "$LOG_FILE" 2>&1 & @@ -200,11 +211,26 @@ SERVER_PID=$! log "✓ Dev server started with PID $SERVER_PID" # 7. Warm up the main application routes -log "Warming up main application routes..." -if curl -s -o /dev/null --max-time 30 http://localhost:3001/ 2>/dev/null; then - log "✓ Main routes pre-compiled" +# We poll until the dev server responds, up to a configurable timeout. This +# gives us a concrete "dev run -> preview ready" duration that callers can +# use for more granular sandbox timing analysis. +MAX_DEV_WAIT_SECONDS=${UMAMI_DEV_WAIT_SECONDS:-60} +log "Warming up main application routes (up to ${MAX_DEV_WAIT_SECONDS}s)..." +DEV_SERVER_READY=0 +for ((i=1; i<=MAX_DEV_WAIT_SECONDS; i++)); do + if curl -s -o /dev/null --max-time 5 http://localhost:3001/ 2>/dev/null; then + DEV_SERVER_READY=1 + break + fi + sleep 1 +done + +DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) + +if [[ "$DEV_SERVER_READY" -eq 1 ]]; then + log "✓ Main routes pre-compiled (ready after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s)" else - log "Warning: Route warm-up timed out or failed (non-critical)" + log "Warning: Route warm-up timed out after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s (non-critical)" fi log "" @@ -225,3 +251,13 @@ log "Hot reload is enabled - changes will be reflected automatically" log "" log "To stop the server: kill $SERVER_PID" log "" + +# Emit a final structured timing summary that external tools (like the +# Niteshift benchmark CLI) can parse from logs to build a detailed timing +# table for sandbox provisioning and runtime behavior. +SCRIPT_TOTAL_DURATION_S=$((SECONDS - SCRIPT_START_SECONDS)) +TIMING_JSON=$(printf '{"pnpm_install_s":%s,"dev_run_to_preview_s":%s,"script_total_s":%s}' \ + "${PNPM_INSTALL_DURATION_S:-0}" \ + "${DEV_SERVER_TO_PREVIEW_DURATION_S:-0}" \ + "${SCRIPT_TOTAL_DURATION_S}") +log "NITESHIFT_TIMING_JSON=${TIMING_JSON}" From 7f201e6e59043e7558b9b4002864cc64902dc0db Mon Sep 17 00:00:00 2001 From: Yann MAHE Date: Thu, 4 Dec 2025 10:02:26 -0500 Subject: [PATCH 2/4] one call --- niteshift-setup.sh | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/niteshift-setup.sh b/niteshift-setup.sh index ced6bfde..328b9477 100755 --- a/niteshift-setup.sh +++ b/niteshift-setup.sh @@ -211,26 +211,16 @@ SERVER_PID=$! log "✓ Dev server started with PID $SERVER_PID" # 7. Warm up the main application routes -# We poll until the dev server responds, up to a configurable timeout. This -# gives us a concrete "dev run -> preview ready" duration that callers can -# use for more granular sandbox timing analysis. +# Use a single blocking curl to capture an accurate "dev run -> preview ready" +# duration while still honoring a configurable max wait. MAX_DEV_WAIT_SECONDS=${UMAMI_DEV_WAIT_SECONDS:-60} -log "Warming up main application routes (up to ${MAX_DEV_WAIT_SECONDS}s)..." -DEV_SERVER_READY=0 -for ((i=1; i<=MAX_DEV_WAIT_SECONDS; i++)); do - if curl -s -o /dev/null --max-time 5 http://localhost:3001/ 2>/dev/null; then - DEV_SERVER_READY=1 - break - fi - sleep 1 -done - -DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) - -if [[ "$DEV_SERVER_READY" -eq 1 ]]; then +log "Warming up main application routes (max ${MAX_DEV_WAIT_SECONDS}s)..." +if curl -s -o /dev/null --max-time "${MAX_DEV_WAIT_SECONDS}" http://localhost:3001/ 2>/dev/null; then + DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) log "✓ Main routes pre-compiled (ready after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s)" else - log "Warning: Route warm-up timed out after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s (non-critical)" + DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) + log "Warning: Route warm-up failed or timed out after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s (non-critical)" fi log "" From 4e972509ddba390f42242379d2002708db87c20a Mon Sep 17 00:00:00 2001 From: Yann MAHE Date: Thu, 4 Dec 2025 10:40:48 -0500 Subject: [PATCH 3/4] update curl --- niteshift-setup.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/niteshift-setup.sh b/niteshift-setup.sh index 328b9477..b3768c9f 100755 --- a/niteshift-setup.sh +++ b/niteshift-setup.sh @@ -215,7 +215,14 @@ log "✓ Dev server started with PID $SERVER_PID" # duration while still honoring a configurable max wait. MAX_DEV_WAIT_SECONDS=${UMAMI_DEV_WAIT_SECONDS:-60} log "Warming up main application routes (max ${MAX_DEV_WAIT_SECONDS}s)..." -if curl -s -o /dev/null --max-time "${MAX_DEV_WAIT_SECONDS}" http://localhost:3001/ 2>/dev/null; then +DEV_WARMUP_START_SECONDS=$SECONDS +if curl \ + --retry-connrefused \ + --retry "${MAX_DEV_WAIT_SECONDS}" \ + --retry-delay 1 \ + --retry-max-time "${MAX_DEV_WAIT_SECONDS}" \ + --max-time "${MAX_DEV_WAIT_SECONDS}" \ + -s -o /dev/null http://localhost:3001/ 2>/dev/null; then DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) log "✓ Main routes pre-compiled (ready after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s)" else From 52495fb67f8e54f25dd2758b0c32f45c736fc9e4 Mon Sep 17 00:00:00 2001 From: Yann MAHE Date: Thu, 4 Dec 2025 11:19:30 -0500 Subject: [PATCH 4/4] polling --- niteshift-setup.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/niteshift-setup.sh b/niteshift-setup.sh index b3768c9f..886e00e3 100755 --- a/niteshift-setup.sh +++ b/niteshift-setup.sh @@ -216,17 +216,19 @@ log "✓ Dev server started with PID $SERVER_PID" MAX_DEV_WAIT_SECONDS=${UMAMI_DEV_WAIT_SECONDS:-60} log "Warming up main application routes (max ${MAX_DEV_WAIT_SECONDS}s)..." DEV_WARMUP_START_SECONDS=$SECONDS -if curl \ - --retry-connrefused \ - --retry "${MAX_DEV_WAIT_SECONDS}" \ - --retry-delay 1 \ - --retry-max-time "${MAX_DEV_WAIT_SECONDS}" \ - --max-time "${MAX_DEV_WAIT_SECONDS}" \ - -s -o /dev/null http://localhost:3001/ 2>/dev/null; then - DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) +DEV_SERVER_READY=0 +for ((i=1; i<=MAX_DEV_WAIT_SECONDS; i++)); do + if curl -s -o /dev/null --max-time 5 http://localhost:3001/ 2>/dev/null; then + DEV_SERVER_READY=1 + break + fi + sleep 1 +done + +DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) +if [[ "$DEV_SERVER_READY" -eq 1 ]]; then log "✓ Main routes pre-compiled (ready after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s)" else - DEV_SERVER_TO_PREVIEW_DURATION_S=$((SECONDS - DEV_PHASE_START_SECONDS)) log "Warning: Route warm-up failed or timed out after ${DEV_SERVER_TO_PREVIEW_DURATION_S}s (non-critical)" fi