From 64e16f2ceeb97997e6c235450c2da15b50155835 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Sat, 28 Nov 2026 19:06:05 +0100 Subject: [PATCH 1/2] docs(openspec): amend the large deploy body of add-load-tests The spec asked for the 200 MB deploy body to be streamed in chunks and not held per virtual user. k6 cannot send that: k6/http accepts a request body only as a string, an object or an ArrayBuffer, and every virtual user keeps its own copy of what it holds. The load generator would hit its own memory limit before the Ingot pod it measures, so the number would describe the generator, not Ingot. D10 now generates the body per iteration, sends it once and drops it, so at most one body exists per in-flight request. The 200 MB size gets its own executor whose concurrency is capped by the memory limit of the generator pod, and the run refuses to start when the cap does not fit. Generation happens before the request, so the measured request duration excludes it. The code is group 9 of tasks.md and ships as fix(loadtest). --- openspec/changes/add-load-tests/design.md | 64 ++++++++++++++++++- openspec/changes/add-load-tests/proposal.md | 1 + .../add-load-tests/specs/load-testing/spec.md | 59 ++++++++++++++++- openspec/changes/add-load-tests/tasks.md | 44 ++++++++++++- 4 files changed, 161 insertions(+), 7 deletions(-) diff --git a/openspec/changes/add-load-tests/design.md b/openspec/changes/add-load-tests/design.md index 1d4b848ea4..dd7bcedbd3 100644 --- a/openspec/changes/add-load-tests/design.md +++ b/openspec/changes/add-load-tests/design.md @@ -126,13 +126,65 @@ The dashboard JSON is checked in at `loadtest/grafana/ingot-load-tests.json`. Bu interface would lose it on the next rebuild of the instance and leave no review of changes. The JSON is validated by a unit test that checks the variables and the panel titles. -### D10. Seeded test data and no login throttling +### D10. Seeded test data, a per-iteration 200 MB body and no login throttling `setup()` creates the fixtures through the Ingot admin API, the same path a user takes, and never writes to the database or the bucket directly: artifacts of the sizes the scenarios use, versions for the metadata and resolve scenarios, tokens and users for auth, and the search index inputs. A failed fixture call fails the setup. A fixed seed makes the bytes and the checksums identical -across runs. The 200 MB deploy body is streamed in chunks from the seeded generator and is never held in memory per virtual user. -Login throttling stays at its default, off, so that the auth scenario measures the credential path and not the throttle. +across runs. Login throttling stays at its default, off, so that the auth scenario measures the credential path and not the throttle. + +The 200 MB deploy body is generated per iteration from the seeded generator, sent once, and dropped when the iteration returns. It +is not streamed and it is not kept between iterations. Its concurrency is capped by its own executor, so that the bodies in memory +at once fit the memory of the load generator pod. + +Why: k6 cannot send a streamed request body. `k6/http` takes a request body as `RequestBody = string | StructuredRequestBody | +ArrayBuffer` (`loadtest/node_modules/@types/k6/http/index.d.ts`, line 339, from `@types/k6` pinned in `loadtest/package.json`), and +`experimental/streams` is not accepted there. Every virtual user runs its own JavaScript runtime, so any body a virtual user keeps is +a full copy per virtual user. The code on main does this: `scenarios/deploy.ts` keeps one body per size in the module-level Map +`bodies`, so every virtual user that deploys holds its own 200 MB copy. This amendment removes that copy. + +Decision: + +- Each 200 MB deploy generates its body with `generateArtifact` and the seed of its size, so the bytes and the checksum are the same + in every run. The body goes to `http.put` as an `ArrayBuffer` and goes out of scope when the iteration returns. +- At most one full body exists per in-flight request. A virtual user runs one request at a time, so the bodies in memory are at most + the virtual users that are inside a 200 MB iteration. +- The 200 MB size runs in its own `constant-arrival-rate` executor whose `maxVUs` is the cap. The open model drops an iteration when + all of those virtual users are busy, so the 200 MB requests in flight never exceed the cap. + +Alternatives considered and rejected: + +- A streaming uploader for the 200 MB size alone. It would send the largest size through another client path than 1 KB, 1 MB and + 50 MB, which makes the 200 MB size incomparable with the others. +- Dropping the 200 MB size. It loses the largest-artifact data point, the one that stresses the storage and memory path that an + operator sizes for. + +Memory rule: + + cap x 200 MiB + headroom <= K6_GENERATOR_MEMORY_LIMIT + +- `cap` is the `maxVUs` of the 200 MB executor. It is derived as the largest integer that satisfies the rule. A cap given for a run + that breaks the rule is refused. +- `200 MiB` is 209,715,200 bytes, `ARTIFACT_SIZES['200MB']` in `loadtest/lib/artifacts.ts`. +- `headroom` covers the k6 runtime and the bodies of the other size executors (1 KB, 1 MB and 50 MB), which hold one body per + in-flight request in the same pod. It is the constant `K6_GENERATOR_HEADROOM` in `loadtest/lib/config.ts`. +- `K6_GENERATOR_MEMORY_LIMIT` is the memory limit of the load generator pod. It is set in `loadtest/lib/config.ts` next to `K6_IMAGE`, + and the runner writes it to `spec.runner.resources.limits.memory` of the `TestRun` in `loadtest/runner/testrun.ts`. The `TestRun` + sets no resources today, so the limit, the headroom and the rule are new with group 9 of tasks.md. +- Open for the maintainer: the k6 runtime is Go, and its default GOGC of 100 lets the heap grow to about twice its live size before a + collection. The headroom must cover that growth, or the runner sets GOGC. Group 9 measures the peak on the cluster before the + value is fixed. + +Keeping generation out of the timing: + +- `k6_http_req_duration_seconds` runs from the send of the request to the end of the response. `http.put` receives the body already + built, so generating the body is not part of it. +- The verdicts read `k6_http_req_duration_seconds` for the p95 (`profiles/step-verdict.ts`), `k6_http_reqs_total` for the error rate + and `k6_dropped_iterations_total` for the dropped iterations. No file under `loadtest/` outside the tests reads + `iteration_duration`, so the iteration duration is not used for any verdict. Checked against main on 2026-11-28. +- One effect is not hidden. The virtual user is busy while it generates, so slow generation can let the arrival rate fall behind + and count dropped iterations, and a dropped iteration fails a step under the pass rule (D3). The generation time of the 200 MB body + is therefore measured on the cluster in group 9, not assumed. ### D11. Reference pod sizes @@ -232,3 +284,9 @@ Decisions of 2026-11-18 by the maintainer: 9. Test data is created in `setup()` through the Ingot admin API (D10). 10. The 200 MB deploy body is streamed and is not held per virtual user (D10). 11. The mirror scenario (task 3.3) runs its live check in group 5 against the in-cluster upstream mock (task 5.3). + +Decision of 2026-11-28 by the maintainer, amending item 10: + +12. The 200 MB deploy body is generated per iteration and sent once, not streamed, because k6 accepts no stream as a request body. + Its concurrency is capped by the memory limit of the load generator pod (D10). Generation is kept out of the measured request + duration, and the amendment ships as the `fix(loadtest)` pull request of group 9 in tasks.md. diff --git a/openspec/changes/add-load-tests/proposal.md b/openspec/changes/add-load-tests/proposal.md index 23145fe75d..4af27a9a46 100644 --- a/openspec/changes/add-load-tests/proposal.md +++ b/openspec/changes/add-load-tests/proposal.md @@ -44,6 +44,7 @@ and the server metrics behind them are read side by side. `size`. - **Documentation.** A how-to `docs/gitbook/contributing/run-the-load-tests.md` and a generated page `docs/gitbook/references/reference-capacities.md` with the measured reference values, both listed in `docs/gitbook/SUMMARY.md`. +- **Amendment of design D10 (2026-11-28).** k6 accepts no stream as a request body, so the 200 MB deploy body is generated per iteration and its concurrency is capped by the memory limit of the load generator pod, and this amendment ships under `fix(loadtest)` as group 9 of tasks.md. ### Breaking changes diff --git a/openspec/changes/add-load-tests/specs/load-testing/spec.md b/openspec/changes/add-load-tests/specs/load-testing/spec.md index 90a020c779..675af08c99 100644 --- a/openspec/changes/add-load-tests/specs/load-testing/spec.md +++ b/openspec/changes/add-load-tests/specs/load-testing/spec.md @@ -28,8 +28,8 @@ The change SHALL NOT alter the server, the image, the chart defaults or any conf The suite SHALL provide the scenarios `resolve`, `resolve-miss`, `metadata`, `deploy`, `mirror`, `auth`, `search-browse` and `dashboard`, and a `mix` scenario that combines them with weights. Every request SHALL carry the tag `scenario:`. Test data -SHALL be created in `setup()` through the Ingot admin API with a fixed seed. The 200 MB deploy body SHALL be streamed in chunks and -SHALL NOT be held in memory per virtual user. +SHALL be created in `setup()` through the Ingot admin API with a fixed seed. The 200 MB deploy body SHALL be generated as described in +the requirement "Large deploy body generated per iteration". #### Scenario: Tag per request @@ -46,6 +46,61 @@ SHALL NOT be held in memory per virtual user. - **WHEN** `resolve-miss` receives a `404` from a group repository - **THEN** the response counts as expected and does not count as an error +### Requirement: Large deploy body generated per iteration + +The 200 MB deploy body SHALL be generated from the seeded generator inside each iteration, sent once, and released when the +iteration returns. The suite SHALL NOT stream the body, because k6 accepts no stream as a request body, and SHALL NOT keep the body +of a virtual user between iterations. + +#### Scenario: One body per in-flight request + +- **WHEN** a 200 MB deploy request is in flight +- **THEN** its virtual user holds exactly one body of 200 MB, and that body is released once the response has been received + +#### Scenario: Body released after the response + +- **WHEN** a 200 MB deploy iteration returns +- **THEN** no reference to its body remains, and the next 200 MB iteration generates its body again from the seed + +### Requirement: Concurrency cap for the 200 MB deploy + +The 200 MB deploy SHALL run in its own executor whose maximum number of virtual users is the cap of its concurrency. The number of +200 MB requests in flight SHALL NOT exceed that cap. + +#### Scenario: Cap held under saturation + +- **WHEN** the 200 MB deploy executor cannot start an iteration because all of its virtual users are busy +- **THEN** no more than the cap of 200 MB requests are in flight, and the iteration counts as a dropped iteration + +### Requirement: Cap derived from the generator memory limit + +The cap SHALL be the largest whole number that satisfies cap x 200 MiB + headroom <= the memory limit of the load generator pod, where +the limit is the constant `K6_GENERATOR_MEMORY_LIMIT` in `loadtest/lib/config.ts`. The runner SHALL refuse to start a run whose cap, +multiplied by 200 MiB and added to the headroom, exceeds that limit. The refusal SHALL happen before any call to the cluster, and its +message SHALL name both the cap and the memory limit. + +#### Scenario: Cap derived without an override + +- **WHEN** a run is started without a cap +- **THEN** the cap is the largest whole number that satisfies the rule, and the `TestRun` sets the memory limit of the load generator + pod to `K6_GENERATOR_MEMORY_LIMIT` + +#### Scenario: Override over the limit refused + +- **WHEN** a run is started with a cap that makes cap x 200 MiB plus the headroom larger than the memory limit +- **THEN** the runner exits before the first call to the cluster with a message that names the cap and the memory limit, and starts no load + +### Requirement: Body generation outside the measured request + +Body generation SHALL happen before the request call. The measured request duration SHALL exclude body generation, and the verdicts +SHALL NOT use the iteration duration. + +#### Scenario: Request duration excludes generation + +- **WHEN** a 200 MB deploy iteration generates its body and then sends it +- **THEN** the request duration that k6 measures starts when the request is sent, and the time spent generating the body is not part + of it + ### Requirement: Open arrival model Load SHALL be generated with the `constant-arrival-rate` and `ramping-arrival-rate` executors. The suite SHALL NOT use a fixed number diff --git a/openspec/changes/add-load-tests/tasks.md b/openspec/changes/add-load-tests/tasks.md index 40e239d13d..16a93f4272 100644 --- a/openspec/changes/add-load-tests/tasks.md +++ b/openspec/changes/add-load-tests/tasks.md @@ -1,8 +1,8 @@ # Tasks Ordered. Each unit test is written first and seen failing. Task checkboxes stay unchecked in this proposal pull request and are -ticked only in a follow-up that the maintainer asks for. Every task in this change is `test(load)`, so each pull request below is one -commit type. +ticked only in a follow-up that the maintainer asks for. Groups 1 to 8 are `test(load)`, so each pull request of the stack is one +commit type. Group 9 amends design.md D10 and ships as its own `fix(loadtest)` pull request, not as part of the stack. The code ships as a stack of small pull requests, about 400 lines each. Each pull request is based on the branch of the one before it in the stack, and is retargeted to `main` when its predecessor is merged. Each group ends with the task that opens its pull request @@ -25,6 +25,7 @@ Pull request: `test(load): add the typescript scaffolding for k6 load tests` `loadtest/lib/artifacts.ts` with the seeded generator for the sizes 1 KB, 1 MB, 50 MB and 200 MB, `loadtest/lib/auth.ts` and `loadtest/lib/checks.ts` for Basic and token headers and the shared checks, and `loadtest/lib/setup.ts`, which creates the fixtures in `setup()` through the admin API only (a unit test with a fake admin client asserts that no other client is called). + Superseded by group 9: the 200 MB body is generated per iteration and is no longer produced as chunks (design.md D10). - [x] 1.4 Test: `loadtest/lib/sizes.test.ts` asserts the five reference sizes N, T, S, M and L with their CPU and memory values, and that the requests of every size equal its limits. Then add `loadtest/lib/sizes.ts`, the one file that defines them. - [x] 1.5 Add `loadtest/lib/thresholds.ts`, the one file that declares the thresholds of every scenario, and a unit test that @@ -41,6 +42,7 @@ Pull request: `test(load): add the resolve, deploy and mix scenarios` against a fixture. Then add `loadtest/scenarios/resolve.ts` with the executor, the tag `scenario:resolve` and the expected status set. - [x] 2.2 Add `loadtest/scenarios/deploy.ts` (PUT of 1 KB, 1 MB, 50 MB and 200 MB artifacts, several versions concurrently, the 200 MB body streamed from the generator of 1.3 and not held per virtual user). Verify the executor and the sizes against the artifacts of 1.3. + Superseded by group 9: the 200 MB body is generated per iteration, not streamed, and is not held per virtual user (design.md D10). - [x] 2.3 Add `loadtest/scenarios/mix.ts`, which combines `resolve` and `deploy` with weights set in one file. Test: the weights sum to 1 and every scenario present is in the mix. Later scenarios join the weights in group 3. - [ ] 2.4 Verify: each scenario runs with `k6 run --iterations 1` against an Ingot started locally with the default settings, and passes @@ -161,3 +163,41 @@ Pull request: `test(load): add result records and the reference capacities page` endpoint. - [x] 8.6 Open the pull request `test(load): add result records and the reference capacities page` on the branch of 7.3, with the template filled, as the last pull request of the stack. Verify with `gh pr view --json title,body,files`. + +## 9. Large deploy body per iteration (fix(loadtest)) + +Pull request: `fix(loadtest): generate the large deploy body per iteration and cap its concurrency` + +Amends design.md D10. Branched from the remote main branch that already contains the merged proposal of this amendment. Each step +is a test commit, `test(loadtest)`, written and seen failing first, and then a code commit, `fix(loadtest)`, that makes it pass. Every +test follows F.I.R.S.T.: no sleep, no clock read, no shared state, no network, and the temporary files of a test live in a temporary +directory. Task checkboxes are ticked in the follow-up pull request, never in this one. + +- [ ] 9.1 Test (`test(loadtest)`): `loadtest/lib/body-cap.test.ts` asserts the derived cap, the largest whole number with cap x 200 MiB + plus headroom at most the memory limit, a limit too small for one body refuses with a cap of zero, and an override over the rule is + refused with a message that names the cap and the memory limit. +- [ ] 9.2 Add `loadtest/lib/body-cap.ts` as a pure function that derives the cap and checks an override (`fix(loadtest)`). Verify: + the test of 9.1 passes. +- [ ] 9.3 Test (`test(loadtest)`): `loadtest/lib/config.test.ts` asserts that `K6_GENERATOR_MEMORY_LIMIT` and `K6_GENERATOR_HEADROOM` + are Kubernetes memory quantities and that the headroom is positive and below the limit. `loadtest/runner/testrun.test.ts` asserts + that the `TestRun` sets `spec.runner.resources` with requests equal to limits, both at the memory limit. +- [ ] 9.4 Add the two constants to `loadtest/lib/config.ts` next to `K6_IMAGE`, with the values measured in task 9.9, and write the + resources into the `TestRun` in `loadtest/runner/testrun.ts` (`fix(loadtest)`). Verify: the tests of 9.3 pass. +- [ ] 9.5 Test (`loadtest/scenarios/deploy.test.ts`, `test(loadtest)`): a pure function of `loadtest/scenarios/deploy-plan.ts`, which + takes the generator and the sender as arguments, generates the 200 MB body before the PUT, and generates it again on the next + call, so no body is kept. A fake generator asserts that the bytes of the call have the seeded SHA-1 of task 1.3. +- [ ] 9.6 Add that function to `loadtest/scenarios/deploy-plan.ts` and remove the module-level `bodies` Map from + `loadtest/scenarios/deploy.ts` so that the 200 MB body is generated per iteration (`fix(loadtest)`). Verify: the test of 9.5 passes. +- [ ] 9.7 Test (`test(loadtest)`): `loadtest/profiles/options.test.ts` asserts that the deploy profile runs the 200 MB size in its own + `constant-arrival-rate` executor whose `maxVUs` equals the cap, and that no other size runs in that executor. +- [ ] 9.8 Wire the 200 MB executor into `loadtest/profiles/options.ts` with the cap of 9.2 (`fix(loadtest)`). Verify: the test of 9.7 + passes. +- [ ] 9.9 Test (`test(loadtest)`): `loadtest/runner/steps.test.ts` asserts that a run whose cap breaks the rule is refused before the + install step and before any call to the cluster, and that the refusal message names the cap and the memory limit. Then wire the + check into `loadtest/runner/main.ts` as the first step (`fix(loadtest)`). +- [ ] 9.10 Verify on the cluster (no commit): one 200 MB run at the derived cap against the monolith overlay. Record the peak memory of + the load generator pod and the generation time per body. Set `K6_GENERATOR_HEADROOM` and `K6_GENERATOR_MEMORY_LIMIT` from the peak + (design.md D10, the open GOGC point), and run `npm run typecheck` and the unit suite of `loadtest/` with no `.js` or `.mjs` file + under `loadtest/`. +- [ ] 9.11 Open the pull request `fix(loadtest): generate the large deploy body per iteration and cap its concurrency` on main, with + the template filled, as the last task of this change. Verify with `gh pr view --json title,body,files`. From aab9abf00e96d73194694c882f09f4d9779e3e21 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Sat, 28 Nov 2026 19:07:05 +0100 Subject: [PATCH 2/2] docs(openspec): point the generator constants at the cluster measurement Task 9.4 named task 9.9 as the source of the memory values, but the measurement is task 9.10, which runs after the code is in place. --- openspec/changes/add-load-tests/tasks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openspec/changes/add-load-tests/tasks.md b/openspec/changes/add-load-tests/tasks.md index 16a93f4272..98704cb525 100644 --- a/openspec/changes/add-load-tests/tasks.md +++ b/openspec/changes/add-load-tests/tasks.md @@ -181,7 +181,7 @@ directory. Task checkboxes are ticked in the follow-up pull request, never in th - [ ] 9.3 Test (`test(loadtest)`): `loadtest/lib/config.test.ts` asserts that `K6_GENERATOR_MEMORY_LIMIT` and `K6_GENERATOR_HEADROOM` are Kubernetes memory quantities and that the headroom is positive and below the limit. `loadtest/runner/testrun.test.ts` asserts that the `TestRun` sets `spec.runner.resources` with requests equal to limits, both at the memory limit. -- [ ] 9.4 Add the two constants to `loadtest/lib/config.ts` next to `K6_IMAGE`, with the values measured in task 9.9, and write the +- [ ] 9.4 Add the two constants to `loadtest/lib/config.ts` next to `K6_IMAGE`, with provisional values that task 9.10 replaces with the measured ones, and write the resources into the `TestRun` in `loadtest/runner/testrun.ts` (`fix(loadtest)`). Verify: the tests of 9.3 pass. - [ ] 9.5 Test (`loadtest/scenarios/deploy.test.ts`, `test(loadtest)`): a pure function of `loadtest/scenarios/deploy-plan.ts`, which takes the generator and the sender as arguments, generates the 200 MB body before the PUT, and generates it again on the next