feat(serverless): implement warm container pool for function reuse#594
feat(serverless): implement warm container pool for function reuse#594poyrazK wants to merge 39 commits into
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (45)
📝 WalkthroughWalkthroughThis PR implements warm container pooling for serverless-style function execution. It introduces a pool manager that maintains warm instances per function, scales based on demand, reaps idle instances, and integrates with function invocation to prefer warm execution over cold starts. The implementation spans pool contracts and manager, command validation, a Firecracker guest agent, backend-specific pool methods (Docker, Firecracker with vsock, libvirt with console), database schema, and service integration. ChangesWarm Container Pool Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- pool.go: fix variable shadowing (pool -> existingPool/newPool) - pool.go: remove unused deadline variables in waitForWarmInstance/waitWithBackpressure - libvirt/adapter.go: replace fragile shell-prompt detection with gap-based (1s) exec completion - postgres: add migration 114 for pool_config column
Security hardening for PR #594 findings: 1. Firecracker agent: replace shell execution (sh -c) with direct exec + command validation. Block dangerous patterns (shell operators, path traversal, command substitution). 2. FunctionService: add CommandValidator to validate commands before ExecInInstance in pooled invocation path. 3. Add unit tests for pool manager and command validator. 4. Fix mockCompute in resilient_compute_test to implement the new pool interface methods (StartPoolInstance, ExecInInstance, GetInstanceReady).
CI was failing because golangci-lint v1.64.8 was being used but the config file uses version: "2" format. Upgrade CI to v2.3.2.
The function repository was updated to include pool_config column but the unit tests were not updated to match.
The golangci-lint v2 import path is github.com/golangci/golangci-lint/v2/cmd/golangci-lint
Summary
Implements per-function warm container/VM pools to eliminate cold starts on repeated function invocations. Containers/VMs are reused across invocations, reducing latency from 2-5s to ~100ms.
Changes
New Files
internal/core/ports/pool.go- PoolManager interface, PoolConfig, PoolInstance, PoolStatsinternal/core/pool/pool.go- PoolManagerImpl, FunctionPool with Acquire/Release/Reapercmd/firecracker-agent/- Guest agent skeleton for Firecracker vsock execModified Files
internal/core/domain/function.gointernal/core/ports/compute.gointernal/core/services/function.gointernal/repositories/docker/adapter.gointernal/repositories/firecracker/adapter.gointernal/repositories/libvirt/adapter.gointernal/repositories/libvirt/libvirt_client.gointernal/repositories/libvirt/real_client.gointernal/repositories/libvirt/templates.gointernal/repositories/postgres/function_repo.goKey Design Decisions
Backend Support Matrix
Test Plan
pool_config: {min_size: 2, max_size: 5}Notes
Future Enhancements
Summary by CodeRabbit
Release Notes