Skip to content

feat(core): Scale expression isolate pool to 0 after inactivity#28472

Open
ivov wants to merge 1 commit intomasterfrom
cat-2781-scale-isolate-pool-down-to-0-after-inactivity
Open

feat(core): Scale expression isolate pool to 0 after inactivity#28472
ivov wants to merge 1 commit intomasterfrom
cat-2781-scale-isolate-pool-down-to-0-after-inactivity

Conversation

@ivov
Copy link
Copy Markdown
Member

@ivov ivov commented Apr 14, 2026

https://linear.app/n8n/issue/CAT-2781/

  • I have seen this code, I have run this code, and I take responsibility for this code.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Bundle Report

Changes will increase total bundle size by 42 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
editor-ui-esm 45.75MB 42 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/constants-*.js 42 bytes 3.14MB 0.0%

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 9 files

Architecture diagram
sequenceDiagram
    participant CLI as CLI / BaseCommand
    participant Pool as IsolatePool
    participant Bridge as RuntimeBridge (V8 Isolate)
    participant Obs as Observability / Metrics

    Note over CLI,Obs: Engine Initialization
    CLI->>Pool: initialize()
    Pool->>Bridge: NEW: createBridge() x N
    Pool->>Obs: reportPoolSize(N)
    Pool->>Pool: NEW: startIdleTimer(idleTimeoutMs)

    Note over CLI,Obs: Normal Request Flow (Activity)
    CLI->>Pool: acquire()
    Pool->>Pool: CHANGED: startIdleTimer() (Reset)
    Pool-->>CLI: return bridge
    Pool->>Bridge: execute expression
    CLI->>Pool: release(bridge)
    Pool->>Bridge: dispose()
    Pool->>Bridge: replenish()

    Note over CLI,Obs: NEW: Scale-to-Zero Flow (Inactivity)
    Pool->>Pool: idleTimer expires
    Pool->>Pool: scaleToZero()
    Pool->>Pool: waitForReplenishment() (Safety check)
    
    alt isIdle is still true
        Pool->>Bridge: dispose() all warm bridges
        Pool->>Obs: NEW: counter("scaled_to_zero")
        Pool->>Obs: gauge("pool.size", 0)
    end

    Note over CLI,Obs: NEW: Wake-up Flow (Recovery)
    CLI->>Pool: acquire()
    
    alt wasIdle
        Pool->>Pool: isIdle = false
        Pool->>Obs: NEW: counter("scaled_up")
        Pool->>Pool: startIdleTimer()
        Pool->>Pool: replenish() (Scale back to N)
    end

    Pool-->>CLI: throw PoolExhaustedError (While warming)

    loop replenishment
        Pool->>Bridge: createBridge()
        Bridge-->>Pool: ready
        Pool->>Obs: gauge("pool.size", count++)
    end
Loading

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 14, 2026

Merging this PR will degrade performance by 33.02%

❌ 1 regressed benchmark
✅ 31 untouched benchmarks
⏩ 20 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
vm micro: Script Compilation - cache hit (repeated expression) 357.7 µs 534 µs -33.02%

Comparing cat-2781-scale-isolate-pool-down-to-0-after-inactivity (6788235) with master (39189c3)

Open in CodSpeed

Footnotes

  1. 20 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link
Copy Markdown
Contributor

Performance Comparison

Comparing currentlatest master14-day baseline

Memory consumption baseline with starter plan resources

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-heap-used-baseline 114.95 MB 114.05 MB 113.86 MB (σ 0.84) +0.8% +1.0% ⚠️
memory-rss-baseline 291.23 MB 287.98 MB 284.98 MB (σ 42.51) +1.1% +2.2%

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-n8n 1269.76 MB 1269.76 MB 1269.76 MB (σ 0.00) +0.0% +0.0%
docker-image-size-runners 393.00 MB 393.00 MB 391.63 MB (σ 11.06) +0.0% +0.3%

Idle baseline with Instance AI module loaded

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 186.76 MB 186.52 MB 186.34 MB (σ 0.24) +0.1% +0.2% ⚠️
instance-ai-rss-baseline 385.54 MB 388.20 MB 372.63 MB (σ 22.95) -0.7% +3.5%
How to read this table
  • Current: This PR's value (or latest master if PR perf tests haven't run)
  • Latest Master: Most recent nightly master measurement
  • Baseline: Rolling 14-day average from master
  • vs Master: PR impact (current vs latest master)
  • vs Baseline: Drift from baseline (current vs rolling avg)
  • Status: ✅ within 1σ | ⚠️ 1-2σ | 🔴 >2σ regression

@ivov ivov requested a review from despairblue April 14, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant