mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 14:57:54 -05:00
fix(lambda): make the code-volume populate concurrency configurable (#2830)
Concurrent first-time code-volume populates are capped by a semaphore sized Math.max(2, availableProcessors() / 2). The JVM honours the container's cgroup CPU quota, so a CPU-constrained Floci container derives 2 permits and concurrent cold starts of *distinct* large functions complete in waves of two instead of in parallel. Measured on main, six distinct functions with 41MB packages, all cold, fired concurrently, varying only the quota on Floci's own container: unlimited (16 cpu) -> 8 permits -> one wave of 6 -> 8.3s --cpus=8 -> 4 permits -> waves of 4, 2 -> 13.2s --cpus=4 -> 2 permits -> waves of 2,2,2 -> 19.2s The wave sizes track the formula exactly, which rules out generic CPU starvation - that would slow all six uniformly rather than produce discrete equal-size waves. The populate is IO-bound (creating a helper container and streaming a tar into it), so CPU count is a weak proxy for how many the Docker daemon can absorb. The cap itself is still worth having: the daemon overload it was added to prevent is real. What was missing is a way to decouple it from the CPU allocation, so this adds floci.services.lambda.code-volume-populate-concurrency (FLOCI_SERVICES_LAMBDA_CODE_VOLUME_POPULATE_CONCURRENCY) and leaves the derived default untouched. Values below 1 fall back to the derived default with a warning: zero permits would deadlock every populate, and a negative Semaphore count would make acquire() block until that many releases arrived. The semaphore becomes an instance field so the permit count can come from config. Floci runs a single @ApplicationScoped launcher, so it is still one gate for the whole emulator. Refs #2050
This commit is contained in:
1 parent
63a2a60a30
commit
968ff78e25
6 files changed
+134
-6
No files matched your search
@@ -207,6 +207,7 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
|
||||
| `FLOCI_SERVICES_LAMBDA_EXTRA_HOSTS` | *(unset)* | Comma-separated `hostname:ip` entries added to each Lambda container's `/etc/hosts`; `ip` may be `host-gateway`, mirroring `docker run --add-host` |
|
||||
| `FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE` | *(unset)* | Explicit host/IP that spawned Lambda containers use to reach Floci's Runtime API, bypassing auto-detection |
|
||||
| `FLOCI_SERVICES_LAMBDA_CONTAINER_NAME_PREFIX` | `floci` | Base name prefix for spawned Lambda containers and code volumes (e.g. `acme` → `acme-<function>-<id>` containers, `acme-code-<function>-<hash>` volumes). Must be a valid Docker name segment (`[A-Za-z0-9][A-Za-z0-9_.-]*`); invalid values are ignored with a warning |
|
||||
| `FLOCI_SERVICES_LAMBDA_CODE_VOLUME_POPULATE_CONCURRENCY` | `max(2, cpus/2)` | Maximum concurrent first-time code-volume populates. See the note below |
|
||||
| `FLOCI_SERVICES_LAMBDA_EXECUTOR` | `docker` | Execution backend: `docker` (containers) or `kubernetes` (pods) |
|
||||
| `FLOCI_SERVICES_LAMBDA_KUBERNETES_NAMESPACE` | `default` | Namespace Lambda pods are created in |
|
||||
| `FLOCI_SERVICES_LAMBDA_KUBERNETES_LABELS` | *(unset)* | Extra pod labels as comma-separated `key=value` entries |
|
||||
@@ -226,6 +227,25 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
|
||||
docker volume prune --filter label=floci=true
|
||||
```
|
||||
|
||||
!!! note "Concurrent cold starts of large functions"
|
||||
A function whose unpacked code is at least 32 MB has that code streamed once into a
|
||||
read-only Docker volume, so later cold starts mount it instead of copying. Those
|
||||
first-time *populates* are capped — a burst of them overwhelms the Docker daemon — and
|
||||
the default cap is `max(2, cpus/2)`, derived from the CPU count the JVM sees.
|
||||
|
||||
Because the JVM honours the container's cgroup CPU quota, running Floci with a small CPU
|
||||
allocation collapses the cap to 2, and a burst of cold starts across *distinct* large
|
||||
functions completes in waves of two rather than in parallel. Six such functions invoked
|
||||
at once take roughly three times the wall-clock of one. Raise the cap to decouple it from
|
||||
the CPU allocation:
|
||||
|
||||
```bash
|
||||
FLOCI_SERVICES_LAMBDA_CODE_VOLUME_POPULATE_CONCURRENCY=8
|
||||
```
|
||||
|
||||
Only first-time populates are gated. Warm containers, already-populated volumes, and
|
||||
functions under 32 MB are never serialised by this.
|
||||
|
||||
### Runtime API host override
|
||||
|
||||
When a Lambda container starts, it calls back into Floci's Runtime API to fetch
|
||||
|
||||
Reference in new issue
Block a user