@mark1russell7/capacity 0.0.0-bootstrap.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1107 -1
  3. package/build/index.d.ts +858 -0
  4. package/build/index.d.ts.map +1 -0
  5. package/build/index.js +1713 -0
  6. package/build/index.js.map +1 -0
  7. package/build/instance-0n6WhJzF.d.ts +782 -0
  8. package/build/instance-0n6WhJzF.d.ts.map +1 -0
  9. package/build/instance-check-CAuD9L4Z.js +1711 -0
  10. package/build/instance-check-CAuD9L4Z.js.map +1 -0
  11. package/build/schema.d.ts +69 -0
  12. package/build/schema.d.ts.map +1 -0
  13. package/build/schema.js +315 -0
  14. package/build/schema.js.map +1 -0
  15. package/limits/alerts-routes.line.json +78 -0
  16. package/limits/alerts-scale.limits.json +10 -0
  17. package/limits/alerts-start-gate.limits.json +1149 -0
  18. package/limits/alerts-start-routes-limit-home.bracket.json +543 -0
  19. package/limits/alerts-start-routes-limit-mid.bracket.json +464 -0
  20. package/limits/alerts-start-routes-limit.bracket.json +579 -0
  21. package/limits/alerts-tail-gate.limits.json +610 -0
  22. package/package.json +79 -4
  23. package/src/app-check.ts +477 -0
  24. package/src/app-metrics.ts +105 -0
  25. package/src/app.ts +239 -0
  26. package/src/check.ts +228 -0
  27. package/src/composition.ts +680 -0
  28. package/src/demand.ts +312 -0
  29. package/src/fit.ts +153 -0
  30. package/src/forms.ts +358 -0
  31. package/src/gate.ts +237 -0
  32. package/src/index.ts +142 -0
  33. package/src/instance-check.ts +122 -0
  34. package/src/instance.ts +84 -0
  35. package/src/knee.ts +606 -0
  36. package/src/law.ts +215 -0
  37. package/src/limit.ts +112 -0
  38. package/src/names.ts +19 -0
  39. package/src/observe.ts +74 -0
  40. package/src/program.ts +74 -0
  41. package/src/scale.ts +617 -0
  42. package/src/schema.ts +260 -0
  43. package/src/value.ts +206 -0
  44. package/src/workload-check.ts +130 -0
  45. package/src/workload.ts +88 -0
package/README.md CHANGED
@@ -1,3 +1,1109 @@
1
1
  # @mark1russell7/capacity
2
2
 
3
- This version is a placeholder. The release workflow of https://github.com/metrograph-labs/capacity publishes the real versions. Use a later version.
3
+ This package has the performance and capacity models. A law gives one measure of a subject as a function of its load variables, with an interval. A workload gives the load. An instance type gives the resources of one instance, and a limit set gives the ceilings.
4
+
5
+ **State: the [roadmap](../../docs/ROADMAP.md) tells the state of each item.** The first npm release of the package is CAP-8.
6
+
7
+ ## Entries
8
+
9
+ | Entry | What it has |
10
+ | --- | --- |
11
+ | `@mark1russell7/capacity` | The records of a law, a workload, a composition, an instance type, a limit set and the contract of an app, with their checks. It also has the value of a law and of a composition, the catalog of forms, the fit of a law, the algebra of demands and the use of a limit. A browser can import it. |
12
+ | `@mark1russell7/capacity/schema` | The schema of each file, with `readLaw`, `readWorkload`, `readComposition`, `readInstance`, `readLimits` and `readApp`. This entry needs `zod`. |
13
+ | `@mark1russell7/capacity/limits/<id>.json` | Each limit file of the folder `limits`: the limit sets, the brackets and the lines that the lab measured. An app imports its file and uses the values, with no copy. Alerts reads `alerts-routes.line.json` (CAP-116). |
14
+
15
+ The package holds the models and the rules. It measures nothing, and it reads no file.
16
+
17
+ ## A law
18
+
19
+ A law is plain data, thus a law file is JSON. Its format is `capacity-law/1`.
20
+
21
+ | Field | What it is |
22
+ | --- | --- |
23
+ | `id` | The id of the law, for example `node-http/reply/cpu`. |
24
+ | `title` | One line that tells a person what the law gives. |
25
+ | `subject` | The id of the server that the runs measured. |
26
+ | `measure` | The quantity that the law gives: an id and a unit, for example `cpu` in `{core}·ms/{request}`. |
27
+ | `variables` | The load variables. Each has an id, a unit, a range and a scale (`linear` or `log`). |
28
+ | `conditions` | Each fact that stays constant in the measurement: the Node version, the CPU model, the limits of the container. |
29
+ | `form` | The math of the law: an id and a Vex program. |
30
+ | `constants` | The fitted numbers that the program reads, each with an id and a value. |
31
+ | `replicates` | More fits of the constants, from resamples of the points. Each row has one number for each constant. |
32
+ | `fit` | The method, the residuals of the law, and each form that lost with its error. |
33
+ | `points` | Optional. Each point that the fit used, in the order of the residuals: its load, its value, the index of its run in `evidence.runs` and the start time of its job. |
34
+ | `evidence` | The CI runs that measured the points: an address, a commit and a time for each. |
35
+ | `noise` | The noise floor of the measure on one CPU model, the CPU model, and the CI runs that measured the floor. |
36
+
37
+ A law holds for the ranges of its variables and for its conditions. A value outside a range is an extrapolation, and the answer says so.
38
+
39
+ Each measure of a law is a cost. Past the range of a variable, no run measured the cost. Thus a value past a range holds: it is not lower than the value at the nearest edge of the ranges. A cost that falls with the load stays flat past the edge, and a cost that rises keeps its law. The rule applies to each replicate. Thus a law that falls past its measures cannot give a cost below 0, or an instance that does not fill at any load.
40
+
41
+ The units are canonical units of `@mark1russell7/quantity`. A request rate is in `{request}/s`. A cost of one request has a unit with `{request}` below the line, for example `{core}·ms/{request}` or `B/{request}`.
42
+
43
+ ### CPU time is in core-seconds
44
+
45
+ A CPU cost of one request is in `{core}·ms/{request}`. A request rate times that cost is in `{core}·ms/s`, and that unit converts to `{core}`.
46
+
47
+ Thus the CPU use of a load compares with the CPU of an instance, and no special rule is necessary. The unit `ms/s` counts nothing in particular, thus it does not convert to `{core}`.
48
+
49
+ ### The form is a program
50
+
51
+ The form of a law is a Vex program, not code of this package. The program reads each variable and each constant by its id. This program is a hinge, where the cost goes up faster after a knee:
52
+
53
+ ```ts
54
+ import { app, lit, ref } from "@mark1russell7/vex";
55
+
56
+ // c0 + c1 * rate + c2 * max(0, rate - knee)
57
+ const hinge = app(
58
+ "add",
59
+ app("add", ref("c0"), app("multiply", ref("c1"), ref("rate"))),
60
+ app("multiply", ref("c2"), app("max", lit(0), app("subtract", ref("rate"), ref("knee")))),
61
+ );
62
+ ```
63
+
64
+ A new form needs no change of this package. The tools of Vex examine and explain a program.
65
+
66
+ ### The doubt is in the replicates
67
+
68
+ A law does not keep an interval for each constant. It keeps the replicates: each row is a fit of all the constants to one resample of the points. Thus the rows keep how the constants move together.
69
+
70
+ Each query evaluates the program with each row and reads its interval from the values. Thus an interval is correct for each query, also for a query that joins laws.
71
+
72
+ ### The residuals are out of sample
73
+
74
+ Each residual of `fit.residuals` compares one measured point with a fit that did not use that point. An absolute residual is the difference. A relative residual is the ratio less 1.
75
+
76
+ ## The value of a law
77
+
78
+ ```ts
79
+ import { lawValue } from "@mark1russell7/capacity";
80
+ import { readLaw } from "@mark1russell7/capacity/schema";
81
+
82
+ const law = readLaw(JSON.parse(text));
83
+ if (law.tag === "ok") {
84
+ const answer = lawValue(law.value, { rate: 3000 });
85
+ // answer.value: { value: 0.135, unit: "{core}·ms/{request}", level: 0.95,
86
+ // interval: { low: 0.1339, high: 0.1359 }, run: { low: 0.1276, high: 0.1424 }, outside: [] }
87
+ }
88
+ ```
89
+
90
+ | Field | What it is |
91
+ | --- | --- |
92
+ | `value` | The value of the program with the constants of the law. |
93
+ | `unit` | The unit of the measure. |
94
+ | `level` | The level of the two ranges. It is 0.95 when the query gives none. |
95
+ | `interval` | The doubt of the law: the share `level` of the values of the replicates. It always holds the value. |
96
+ | `run` | Where one measured run falls: the interval, made wider by the residuals. A gate compares a new run with this range. |
97
+ | `outside` | The variables whose value is outside its range. With a name in this list, the value is an extrapolation. |
98
+
99
+ `lawValue` gives a problem, not a value, in three cases:
100
+
101
+ - The point does not give each variable, or it gives a name that is not a variable.
102
+ - The law has too few replicates or residuals for the level. `leastCount(level)` gives the least count: 40 for the level 0.95.
103
+ - The program has no finite value at the point.
104
+
105
+ `constantIntervals(law)` gives each constant with the interval of its replicates.
106
+
107
+ ## The knee of a law
108
+
109
+ The knee is the first load where the cost of a request starts to grow fast. The edge is the first load where the law has no finite value, for example the capacity of a queue.
110
+
111
+ ```ts
112
+ import { lawKnee } from "@mark1russell7/capacity";
113
+
114
+ const knee = lawKnee(law, "rate", { kind: "slope", factor: 2 });
115
+ // knee.value.knee: { value: 2500, interval: { low: 2453, high: 2548 }, outside: false }
116
+ // knee.value.edge: { value: null, interval: { low: null, high: null }, outside: false }
117
+ ```
118
+
119
+ A rule tells when the cost grows fast. The law obeys the rule at the knee, and not before it.
120
+
121
+ | Rule | The knee |
122
+ | --- | --- |
123
+ | `{ kind: "rise", share }` | The first load where the value is `1 + share` times the value at the start of the search. |
124
+ | `{ kind: "slope", factor }` | The first load where the slope is `factor` times the slope at the start of the search. |
125
+ | `{ kind: "floor", share }` | The first load after the floor where the value is `1 + share` times the floor. The floor of a row is its least value on the grid, before its edge. |
126
+
127
+ The rule `floor` is for a law that falls before it grows, for example a latency with a cold start at a low rate. The knee has the field `floor`: the `load` and the `value` of the floor of the constants.
128
+
129
+ - **Each row has its own floor.** Thus the knee of a replicate is always after its floor, and the interval holds the uncertainty of the floor.
130
+ - **A replicate with no floor above 0** has no knee. The field `noFloor` counts these replicates, and the interval leaves them out.
131
+ - **Too many replicates with no floor** give a problem. The interval can leave out the replicates of one tail of the level, for example 25 of 1000 at the level 0.95.
132
+
133
+ The search goes along the range of the variable. The options `from` and `to` change it, and the point `at` gives each other variable. The search tests a grid of `KNEE_STEPS` steps on the scale of the variable, then a bisection finds each crossing. The option `steps` changes the count.
134
+
135
+ | Field | What it is |
136
+ | --- | --- |
137
+ | `knee`, `edge` | A crossing: its `value`, its `interval` from the replicates, and `outside`, true when the value is outside the range of the variable. |
138
+ | `value` | The load of the crossing. It is `null` when the search finds no crossing. |
139
+ | `interval` | The share `level` of the crossings of the replicates. An end past the end of the search is `null`. |
140
+ | `search` | The loads where the search starts and stops. |
141
+ | `outside` | The other variables whose value at the point is outside its range. |
142
+
143
+ `lawKnee` gives a problem, not a knee, in these cases:
144
+
145
+ - The variable is not a variable of the law, or the point does not give each other variable.
146
+ - The search range, the rule or the count of steps is not correct. A share is more than 0, and a factor is more than 1.
147
+ - The law has too few replicates for the level.
148
+ - The constants or a replicate give no value at the start of the search. The path names the row.
149
+ - The rule cannot apply at the start: a rise needs a value more than 0, and a slope needs a slope more than 0. A floor must be more than 0.
150
+
151
+ `kneeRuleProblem(rule, path)` examines a rule from data, for example from a plan file. It gives the problem of the rule, or `undefined`.
152
+
153
+ The search finds a pole where the value grows as a power or as a logarithm, also between two floats. At a pole, each step nearer adds as much size as the step before. Near a finite peak, each step nearer adds much less.
154
+
155
+ Two edges in one step of the grid can hide the first edge. Increase `steps` for a law with poles near each other. A finite peak narrower than 1e-9 of a step can look like a pole.
156
+
157
+ ## The reach of a law
158
+
159
+ The reach is the inverse query of one law. It gives the largest load that one amount holds, for example the largest age of a log that fits in a limit of memory.
160
+
161
+ ```ts
162
+ import { quantity } from "@mark1russell7/quantity";
163
+ import { lawReach, limitAmount } from "@mark1russell7/capacity";
164
+
165
+ // The start memory: 200 MB, 40 MB for each day of the log, and 50 kB for each live report.
166
+ const reach = lawReach(law, "days", quantity(0.9, "GiB"), { at: { reports: 2000 } });
167
+ // reach.value.crossing: { value: 16.66, interval: { low: 15.2, high: 18.35 }, outside: false }
168
+
169
+ // The amount of a limit on an instance is the ceiling less the headroom.
170
+ const amount = limitAmount(limits.memory, instance);
171
+ if (amount.tag === "ok") lawReach(law, "days", amount.value, { at: { reports: 2000 } });
172
+ ```
173
+
174
+ `lawReach(law, variable, amount, options)` gives the first load where the law is more than the amount. Before that load, the law holds the amount. Thus for a law that grows along the variable, the crossing is the largest load that holds the amount.
175
+
176
+ - The amount is a quantity. The function converts it to the unit of the measure of the law. The field `amount` of the result is that value.
177
+ - When the law is more than the amount at the start of the search, the crossing is the start.
178
+ - When the law holds the amount on all of the search, the crossing is `null`.
179
+ - A pole is more than each amount, thus the crossing is before the pole.
180
+
181
+ The options, the search and the fields `edge`, `search` and `outside` are as in a knee. The field `crossing` replaces the field `knee`.
182
+
183
+ `lawReach` gives each problem of `lawKnee` that is not about a rule. It also gives a problem for an amount that is not finite, or that does not convert to the unit of the measure.
184
+
185
+ ## The check of a law
186
+
187
+ `checkLaw(law)` gives each problem of a law, with a code and the path of the field. `readLaw(data)` examines the shape of the data first, then it uses `checkLaw`.
188
+
189
+ - Each id is lower-case words. Each unit is a canonical unit.
190
+ - Each range goes from a finite number to a larger finite number. A range on the scale `log` starts above 0.
191
+ - The program reads each variable and each constant, and no other name.
192
+ - The law has a finite value at each corner and at the middle of its ranges.
193
+ - The law has 40 replicates and 40 residuals or more. Each replicate has one finite number for each constant.
194
+ - Each constant is in the range of its replicates.
195
+ - The replicates of each constant have a width. A column of one value gives the code `flat`. A shape at the edge of its search in each fit gives this.
196
+ - Each form that lost has an error, and the form of the law is not in that list.
197
+ - The evidence names one run or more, each with an `https` address, a full commit and a UTC time.
198
+ - A law with points has one point for each residual. Each point gives a finite value of each variable in its range, a finite value and the index of a run of the evidence.
199
+ - The noise has a floor of 0 or more and a CPU model. It names its runs as the evidence does.
200
+
201
+ The noise floor is two standard deviations of the differences of A/A pairs: two equal cases, each in its own container. A difference of two measurements below the floor is not a result. The plan `floor` of the lab measures it each night, on the CPU model of the runner.
202
+
203
+ A law has 8 variables at most.
204
+
205
+ ## The catalog of forms
206
+
207
+ `FORMS` has the forms of a law of one variable, as data. Each form is a sum of terms. A term is a constant times a basis, and the basis is a Vex program. A shape constant changes the shape of a form, not its size.
208
+
209
+ | Form | Value | Shape constants |
210
+ | --- | --- | --- |
211
+ | `constant` | `base` | |
212
+ | `linear` | `base + slope·x` | |
213
+ | `power` | `base + scale·x^exponent` | `exponent` |
214
+ | `fall-power` | `base + excess / x + scale·x^exponent` | `exponent` |
215
+ | `logarithm` | `base + scale·ln(x)` | |
216
+ | `hinge` | `base + slope·x + bend·max(0, x − knee)` | `knee` |
217
+ | `queue` | `base + scale·capacity / (capacity − x)` | `capacity` |
218
+ | `scalability` | `unit·x / (1 + contention·(x − 1) + coherency·x·(x − 1))` | `contention`, `coherency` |
219
+ | `drift` | `base + drift·x + warm·(1 − e^(−x / settle))` | `settle` |
220
+
221
+ The `fall-power` form has a cost at a low load that falls as the load grows, and then a power of the load. The `queue` form is the delay of a queue, and it has no finite value at its capacity. The `scalability` form is the universal scalability law of the throughput at a concurrency. The `drift` form is a measure over the age of a process: a warm-up that settles, and a steady drift.
222
+
223
+ Each shape constant has a grid of start values and bounds. A fit refines the constant inside its bounds:
224
+
225
+ - The `knee` is inside the range of the variable.
226
+ - The `capacity` is past the largest load.
227
+ - The `contention`, the `coherency` and the `settle` time are 0 or more.
228
+ - The `exponent` has no bounds.
229
+
230
+ ```ts
231
+ import { catalogForm, formOf, slopeOf, startOf } from "@mark1russell7/capacity";
232
+
233
+ const hinge = catalogForm("hinge");
234
+ if (hinge !== undefined) {
235
+ // the program of a law: it reads the variable rate and the constants c0, c1, c2 and knee
236
+ const form = formOf(hinge, { variable: "rate", constants: { base: "c0", slope: "c1", bend: "c2" } });
237
+ const slope = slopeOf(hinge, { variable: "rate" });
238
+ const start = startOf(hinge, { x: rates, y: costs });
239
+ // start.value: { constants: [{ id: "base", value: … }, …, { id: "knee", value: … }], rss: … }
240
+ }
241
+ ```
242
+
243
+ - `formOf` and `programOf` give the program of the value. `slopeOf` gives the program of the slope: the change of the value for each unit of the variable. A test compares each slope with a central difference of the value.
244
+ - `formValues` and `formSlopes` evaluate the two programs at some values of the variable.
245
+ - `startOf` gives the least-squares fit of one form. It is `fitSeparable` of `@mark1russell7/rigor-statistics`. At each value on the grid of each shape constant, least squares fits the constants of the terms. Then a golden-section search refines each shape constant inside its bounds.
246
+ - `separableOf` gives a form as a separable model of `@mark1russell7/rigor-statistics`. Its design has one column for each term.
247
+
248
+ A form that holds another form as a special case fits at least as well. For example, a hinge with `bend` 0 is a line. Thus the sum of the squared residuals of a hinge start is not larger than that of the line. The refine does not increase the sum. A property test holds this order for six pairs of forms.
249
+
250
+ ## The fit of a law
251
+
252
+ `fitLaw` fits a law of one variable to its points. It gives the form, the constants, the replicates and the record of the fit of a law.
253
+
254
+ ```ts
255
+ import { fitLaw } from "@mark1russell7/capacity";
256
+
257
+ const result = fitLaw({ x: rates, y: costs }, { binding: { variable: "rate" }, residual: "relative" });
258
+ if (result.tag === "ok") {
259
+ const { form, constants, replicates, fit, ranks } = result.value;
260
+ // ranks: each form that competed, best first, with the error of its held-out residuals
261
+ }
262
+ ```
263
+
264
+ - **The rank:** each form of the catalog competes. The form with the smallest root mean square of its held-out residuals wins.
265
+ - **The groups:** by default, the points of one load are one group. The held-out fit holds out each group, and the bootstrap draws whole groups. The option `groups` gives other groups.
266
+ - **The groups of the bootstrap:** the option `bootstrapGroups` gives the groups that the bootstrap draws. The default is the list `groups`. A plan that fixes its loads has no random load. Thus its bootstrap draws the independent units of its data, for example whole jobs.
267
+ - **The least count of groups:** a run draws as many groups as the data has, and a fit does not see their order. Thus `g` groups give `bootstrapDraws(g)` different draws: 35 for 4 groups. The interval of the level 0.95 needs 40 values, thus `leastGroups(0.95)` is 5. With fewer groups of the bootstrap, the fit gives an error.
268
+ - **The replicates:** each run of the bootstrap fits the winner to a resample of the groups of the bootstrap. The default is 1000 runs. A law needs 40 replicates for the level 0.95.
269
+ - **The losers:** the record keeps each other form with a held-out prediction at each point. The list `ranks` also keeps each form with no fit, with its reason.
270
+ - **A relative fit:** with `residual: "relative"`, the fit uses the weights `1 / y^2`. Thus it fits the ratios, not the differences.
271
+ - **The interval of a knee:** `constantIntervals` gives the interval of each constant from the replicates. For a hinge, this is the interval of its knee.
272
+
273
+ A test fits a hinge with its knee between two loads. The interval of the knee holds the true knee, and `checkLaw` finds no problem in the law.
274
+
275
+ ## The law files
276
+
277
+ The folder `laws` holds the law files that the lab gives, one file for each law: `laws/<subject>/<plan>/<cpu>/<measure>.law.json`. The workflow `laws.yml` gives the files from the records of named Lab runs. The README of the lab tells the command and the workflow.
278
+
279
+ ```sh
280
+ gh workflow run laws.yml -R metrograph-labs/capacity -f runs='<run of the plan rate> <run of the plan floor>'
281
+ gh run download <laws run> -R metrograph-labs/capacity -n laws-<laws run> -D packages/capacity/laws
282
+ ```
283
+
284
+ A pull request puts the files into the folder. A test reads each file with `readLaw`. The id of each law is its path, and each run of its evidence and its noise is a run of CI. A folder with no law file fails the test.
285
+
286
+ Each file that the workflow gives keeps the points of its fit in the field `points`. The site draws them on the curve of the law. The files of this folder come from fits before the field, thus they have no points yet. The next fit of `laws.yml` gives them.
287
+
288
+ ### The laws of the request rate
289
+
290
+ The Laws run 44987398580 gives the laws of the plan `rate` on the Intel Xeon 6975P-C. Their points are the 200 cases of the 8 jobs of the Lab runs 44964347304 and 44977025221 on that CPU model. The floor jobs of the Lab run 44467543161 give the noise. Each law has 1000 replicates, and the bootstrap draws whole jobs. Each interval holds 0.95 of the replicates.
291
+
292
+ | Measure | Form | Knee, or a constant of the form | Range, requests each second | Held-out error |
293
+ | --- | --- | --- | --- | --- |
294
+ | `cpu.request` | power | exponent −0.481 [−0.490, −0.471] | 100 to 36000 | 0.104 |
295
+ | `memory` | hinge | constant `knee` 13840 [11200, 16880] | 100 to 36000 | 0.012 |
296
+ | `memory.high` | hinge | constant `knee` 14940 [11000, 17890] | 100 to 36000 | 0.012 |
297
+ | `latency.p50` | no law | | | |
298
+ | `latency.p90` | fall-power | knee 3289 [3076, 3507] | 100 to 33000 | 0.497 |
299
+ | `latency.p99` | hinge | knee 6840 [5750, 8524] | 1000 to 33000 | 0.445 |
300
+
301
+ - **The held-out error** is the root mean square of the relative held-out residuals.
302
+ - **The CPU time of each request** falls as the rate increases.
303
+ - **The memory** increases by approximately 80 B for each request each second, up to the constant `knee` of the hinge. After it, the memory stays approximately flat.
304
+ - **The range of the latency laws.** A latency law keeps the points where the subject served 0.97 of the offered rate or more. Thus its range ends at 33000. The tail count cuts the rates 100 and 300 from the law of the 99th percentile.
305
+ - **The knee of a latency** is the first rate after its floor where the latency is more than two times that floor (the rule `floor` of the plan, with the share 1). The 90th percentile has its knee at 3289, and the 99th percentile at 6840.
306
+ - **The median has no law.** In each replicate, the exponent of its best form is at the end of its search, and `checkLaw` refuses the flat column. The plan marks this problem as known until CAP-57. The file of CAP-17 is removed. Its fit kept the points past the limit of the core, and it has no served share.
307
+ - **The Intel Xeon Platinum 8573C and the AMD EPYC 9V45 have no law.** Each had one job of 25 points. The bootstrap draws whole jobs, thus a law needs 5 jobs (CAP-58).
308
+
309
+ A test of the lab reads these files with the plan `rate`. Each measure of the plan has a law on each CPU model of the folder, except a measure with a known mark. Each law has the served share and the tail count of its measure. Each law also has a finite value at each end of its range and a held-out error below 1. Each knee and its interval are in the range.
310
+
311
+ ### The laws of the overhead
312
+
313
+ The Laws run 45069050798 gives the laws of the plan `overhead` on the Intel Xeon 6975P-C. A point is the value of the service subject less the value of the bare subject, in one pair of one job. The points come from the 9 jobs on that CPU model of the Lab runs 45061643369, 45063129123 and 45066776472. These runs have one commit of the subjects. The floor jobs of the Lab run 44467543161 give the noise.
314
+
315
+ | Measure | Form | At 100 requests each second | At 8000 requests each second | Held-out error |
316
+ | --- | --- | --- | --- | --- |
317
+ | `cpu.request.overhead` | logarithm | 0.232 [0.215, 0.248] {core}·ms | 0.064 [0.060, 0.069] {core}·ms | 0.019 {core}·ms |
318
+ | `memory.overhead` | power | 1.25 [1.14, 1.36] MB | 9.94 [9.68, 10.3] MB | 1.39 MB |
319
+ | `memory.high.overhead` | fall-power | 1.12 [0.79, 1.49] MB | 9.97 [9.64, 10.4] MB | 2.13 MB |
320
+ | `latency.p50.overhead` | no law | | | |
321
+ | `latency.p90.overhead` | queue | −0.039 [−0.202, 0.134] ms | 10.4 [9.39, 11.5] ms | 1.81 ms |
322
+ | `latency.p99.overhead` | logarithm | 1.04 [0.56, 1.47] ms at 1000 | 13.7 [12.8, 14.4] ms | 3.52 ms |
323
+
324
+ - **The held-out error** is the root mean square of the absolute held-out residuals. A difference can be 0 or less, thus a relative residual has no meaning.
325
+ - **The CPU time of the runner** is 0.232 {core}·ms for each request at 100 requests each second, and 0.064 at 8000. At 8000, the bare subject uses 0.035.
326
+ - **The memory of the runner** is approximately 1.2 MB at 100 requests each second, and approximately 10 MB from 1000 requests each second.
327
+ - **The latency of the runner** has no interval that holds 0, except the 90th percentile at 100 requests each second.
328
+ - **The median has no law.** In each replicate, the exponent of its best form is at the end of its search, as in the plan `rate`. The plan marks this problem as known until CAP-57.
329
+ - **The 99th percentile starts at 1000 requests each second.** The tail count cuts the pairs at 100 and 500 requests each second. Thus its law has 53 points.
330
+ - **The AMD EPYC 7763, 9V45 and 9V74 and the Intel Xeon Platinum 8370C have no law.** Their jobs gave 24, 16, 16 and 8 points.
331
+
332
+ A test of the lab reads these files with the plan `overhead`. Each law names the subject of its base side, and its residual is absolute. Its held-out error is less than its largest value at an end of its range.
333
+
334
+ ### The laws of alerts after AL-172
335
+
336
+ The Laws run 45865927867 gives the laws of six plans of alerts on the Intel Xeon 6975P-C (CAP-37 and CAP-101). It fits the Lab runs 45768940420, 45824688099 and 45824722253, at alerts `a1709b9`.
337
+
338
+ - AL-172 of alerts decreased the live heap of the start (`start.live`) from 177 MB to 81 MB. Thus the laws of the earlier builds do not hold, and these laws replace them.
339
+ - Each law is of the arm `main` at the first start. Its folder is `laws/alerts-runtime/<plan>/xeon-6975p-c/main/first`.
340
+ - A law needs 40 points or more on one CPU model. The jobs on the AMD EPYC models and the Xeon 6973P-C gave fewer points, thus no law.
341
+ - The routes laws of the AMD EPYC 9V74 came from an earlier build. Thus this change removes them.
342
+ - A start that reaches the heap limit of V8 gives no reading. Thus a law sees only the starts that fit. CAP-103 adds the failed starts to the fit.
343
+ - The compositions of alerts add these laws as terms, in [The compositions of alerts](#the-compositions-of-alerts).
344
+
345
+ ### The laws of the events of alerts
346
+
347
+ The plan is `alerts-start-event`. The variable is `event`, the events each second from 0 to 70.
348
+
349
+ | The measure | 0 events each second | 16 events each second | 70 events each second |
350
+ | --- | --- | --- | --- |
351
+ | `ready` | 5.6 s | 5.6 s | 5.6 s |
352
+ | `watch-peak` | 289 MB | 508 MB | 868 MB |
353
+ | `watch-heap-peak` | 124 MB | 248 MB | 464 MB |
354
+ | `watch-cores` | 0.022 core | 0.076 core | 0.197 core |
355
+
356
+ - 5 starts of the 2 Lab runs reached the heap limit of V8, at the rungs 60 and 70.
357
+ - The law `watch-heap-peak` bends at 43 events each second. Part of the bend comes from the starts that failed, because they have no reading.
358
+
359
+ ### The laws of the persons and the feeds of alerts
360
+
361
+ The plans are `alerts-start-persons` and `alerts-start-feeds`. The variables are `persons`, from 1 to 3000, and `feeds`, from 1 to 10000.
362
+
363
+ | The measure | 1 person | 3000 persons | 1 feed | 10000 feeds |
364
+ | --- | --- | --- | --- | --- |
365
+ | `ready` | 5.2 s | 15.7 s | 5.6 s | 16.0 s |
366
+ | `peak` | 262 MB | 511 MB | 271 MB | 689 MB |
367
+ | `watch-peak` | 269 MB | 794 MB | 284 MB | 677 MB |
368
+ | `watch-heap-peak` | 104 MB | 475 MB | 117 MB | 374 MB |
369
+ | `watch-cores` | 0.003 core | 0.948 core | 0.021 core | 0.201 core |
370
+
371
+ - Alerts cannot start with 10000 persons on the 1 GB target. Each start at that rung reached the heap limit of V8.
372
+ - The CPU of the watch grows as a power of the persons, with the exponent 0.74.
373
+
374
+ ### The laws of the routes of alerts
375
+
376
+ The plan is `alerts-start-routes`. The variable is `routes`, from 8 to 18000. Alerts gives it in the line `amounts` of its run.
377
+
378
+ | The measure | 8 routes | 11000 routes | 18000 routes |
379
+ | --- | --- | --- | --- |
380
+ | `ready` | 5.6 s | 7.3 s | 8.5 s |
381
+ | `heap` | 103 MB | 142 MB | 166 MB |
382
+ | `heap-peak` | 114 MB | 159 MB | 176 MB |
383
+ | `peak` | 257 MB | 326 MB | 358 MB |
384
+ | `watch-peak` | 259 MB | 421 MB | 506 MB |
385
+
386
+ - Alerts cannot start with 100000 routes on the 1 GB target. At alerts `a1709b9`, each of the 52 starts at that rung reached the heap limit of V8 (556 MB), in both shapes.
387
+ - The limit of the routes is 40000 routes, from a grid at 20000, 40000, 70000 and 100000 routes (CAP-99).
388
+
389
+ ### The laws of the log of alerts
390
+
391
+ The plan is `alerts-start-log`. The variable is `log`, from 2 MiB to 382 MiB, the range of the contract of alerts.
392
+
393
+ | The measure | 16 MiB | 188 MiB | 382 MiB |
394
+ | --- | --- | --- | --- |
395
+ | `ready` | 5.7 s | 9.8 s | 19.0 s |
396
+ | `heap-peak` | 119 MB | 166 MB | 185 MB |
397
+ | `peak` | 272 MB | 330 MB | 357 MB |
398
+ | `watch-peak` | 291 MB | 333 MB | 345 MB |
399
+ | `watch-heap-peak` | 116 MB | 121 MB | 126 MB |
400
+ | `watch-cores` | 0.021 core | 0.029 core | 0.031 core |
401
+
402
+ - The log does not stop a start on the 1 GB target: each start of each rung was ready.
403
+ - The memory of the process in the watch grows as the logarithm of the log, but the used heap stays almost level. Thus the memory of the log is outside the heap.
404
+ - The CPU of the watch also grows as the logarithm of the log: 7.4 millicores more at 188 MiB than at 16 MiB (CAP-96). A second start from the snapshot uses a constant 0.016 core.
405
+ - The compositions of alerts add the laws `watch-peak`, `watch-heap-peak` and `watch-cores` as terms with a base of 16 MiB.
406
+ - The law `watch-cores` comes from the Lab runs of CAP-107. The other laws of a first start come from older runs, which have no measure `watchCores`. Each law names its runs in `noise.runs`.
407
+
408
+ ### The laws of the open incidents of alerts
409
+
410
+ The plan is `alerts-start-incidents` (CAP-101). The variable is `incidents`, the open incidents from 0 to 1000, at 10 persons.
411
+
412
+ | The measure | 0 incidents | 10 incidents | 1000 incidents |
413
+ | --- | --- | --- | --- |
414
+ | `ready` | 5.7 s | 5.7 s | 6.2 s |
415
+ | `peak` | 271 MB | 271 MB | 319 MB |
416
+ | `watch-peak` | 281 MB | 286 MB | 370 MB |
417
+ | `watch-heap-peak` | 103 MB | 115 MB | 194 MB |
418
+ | `watch-cores` | 0.020 core | 0.021 core | 0.085 core |
419
+
420
+ - Each start of each rung was ready.
421
+ - The compositions of alerts add the laws `watch-peak`, `watch-heap-peak` and `watch-cores` as terms with a base of 10 incidents. The other plans have 10 incidents.
422
+
423
+ ## The gate of the laws
424
+
425
+ The gate tells if new measured values stay in the run ranges of their laws. A pull request that makes a subject slower or larger moves its values out of the ranges. `lawGate` gives the gate, and `lawRead` gives one read.
426
+
427
+ ```ts
428
+ import { lawGate } from "@mark1russell7/capacity";
429
+
430
+ const reads = [{ point: { rate: 1000 }, value: 0.061 }];
431
+ const gate = lawGate([{ law, jobs: [{ job: "job 1", reads }, { job: "job 2", reads }] }]);
432
+ if (gate.outcome === "block") console.log(gate.reason);
433
+ ```
434
+
435
+ - **A read.** A measured value at a load point falls `within`, `high` or `low` against the range `run` of `lawValue`. A point outside the range of a variable gives no read.
436
+ - **A job.** A read of a job that agrees with its law falls on one side with a chance of `(1 - level) / 2` or less. The binomial test of the count of each side gives the p of the job.
437
+ - **A side.** `partialConjunction` joins the p of the jobs for the claim "two jobs or more show this side" (`GATE_JOBS`). One job on an odd runner cannot block alone.
438
+ - **The family.** `holm` corrects the tests of the two sides of each law at the level 0.01 (`GATE_ALPHA`). A rejected side is a block.
439
+ - **A low side is a block too.** The subject is faster or smaller than its law, thus the law is out of date. A new fit must replace it.
440
+ - **No read.** The function `gateOf` of `@mark1russell7/rigor-bench` joins the laws. A law with fewer than two jobs gives no read. So does a law with too few reads to reject a side. A gate with no law gives no read. It does not pass.
441
+
442
+ The caller gives the jobs of each law. Each job measured the subject in the conditions of the law. A job with `noRead` gives no read, for example a job with a noise floor over its limit. The lab gives the jobs, the noise rule and the workflow (CAP-26).
443
+
444
+ A study used the 8 jobs of the laws of the request rate on the Intel Xeon 6975P-C, at eight rates from 1000 to 30000:
445
+
446
+ - With no change, no job had more than one read out of a range on one side.
447
+ - With 0.01 ms more CPU time for each request, each job had 6 of 8 reads of `cpu.request` above the range.
448
+ - With 0.005 ms more, each job had 1 or 2 such reads. That is below a block.
449
+
450
+ These jobs are the evidence of the laws, thus the study is in sample. The Lab runs of CAP-26 test the gate on new jobs.
451
+
452
+ ## A workload
453
+
454
+ A workload is the load on an app: the classes of its requests, each with a rate. It is plain data, thus a workload file is JSON. Its format is `capacity-workload/1`.
455
+
456
+ | Field | What it is |
457
+ | --- | --- |
458
+ | `id` | The id of the workload, for example `shop/peak`. |
459
+ | `title` | One line that tells a person what the workload is. |
460
+ | `classes` | The request classes. Each has an id, a rate and the variables of one request. |
461
+ | `levels` | The amounts that the whole app holds at one time, for example the open connections. |
462
+ | `source` | The origin of the workload: a plan with a note, or the metrics of an app with a window. |
463
+
464
+ ```json
465
+ {
466
+ "format": "capacity-workload/1",
467
+ "id": "shop/peak",
468
+ "title": "The peak hour of a shop",
469
+ "classes": [
470
+ {
471
+ "id": "read",
472
+ "rate": { "value": 900, "unit": "{request}/s" },
473
+ "request": { "reply": { "value": 2, "unit": "KiB" }, "wait": { "value": 5, "unit": "ms" } }
474
+ },
475
+ {
476
+ "id": "write",
477
+ "rate": { "value": 6000, "unit": "{request}/min" },
478
+ "request": { "body": { "value": 4, "unit": "KiB" }, "wait": { "value": 20, "unit": "ms" } }
479
+ }
480
+ ],
481
+ "levels": { "connections": { "value": 400, "unit": "{connection}" } },
482
+ "source": { "kind": "plan", "note": "The forecast of the last week of November." }
483
+ }
484
+ ```
485
+
486
+ Each amount is an amount of `@mark1russell7/quantity`: a value and a canonical unit. The name of a variable or a level is the id of a law variable, thus a law reads it.
487
+
488
+ ### A class is one point
489
+
490
+ A class has one value for each variable of its request. Requests of two sizes are two classes.
491
+
492
+ A law can bend, thus a law at the mean size does not give the mean cost. Give a spread of sizes as more classes, not as one class with a mean.
493
+
494
+ ### What a workload does not have
495
+
496
+ - A workload does not have the state of an instance, for example the size of its heap or its age. A query gives that state.
497
+ - A workload does not have the count of the requests in flight. That count is a rate times a duration, and a law gives the duration.
498
+ - A workload does not tell how a level divides between instances. That is a property of the app.
499
+ - A workload is not a load schedule. A load schedule of `@mark1russell7/rigor-chaos` is the plan of the arrivals of one measured run.
500
+
501
+ ## The algebra of demands
502
+
503
+ A demand is the classes and the levels of a workload, with no name and no source. Each operation takes a demand and gives a demand, or a problem. A workload is a demand, thus each operation takes a workload.
504
+
505
+ | Function | What it gives |
506
+ | --- | --- |
507
+ | `scaleDemand(demand, by)` | A demand that is `by` times as large: each rate and each level, times `by`. |
508
+ | `mergeDemands(first, second)` | The sum of two demands. The rates of one class add, and the levels add. |
509
+ | `shareOf(demand, instances, options)` | The demand on one of `instances` equal instances. A level in `options.whole` does not divide. |
510
+ | `totalRate(demand, unit)` | The sum of the rates of the classes, in `unit`. |
511
+ | `loadPointOf(demand, id, law, given, options)` | The load point of one class for a law. With `options.load` set to `"total"`, the variable `rate` is the total rate. |
512
+ | `instancePointOf(demand, law, given)` | The load point of the instance for a law: the total rate and the levels, with no request. |
513
+
514
+ No operation changes the variables of a request: more clients do not make a request larger.
515
+
516
+ The sum has the laws of addition:
517
+
518
+ - The order and the groups of the demands do not change the sum. They can change the unit of an amount, and not the amount.
519
+ - The demand `NO_DEMAND`, with no class and no level, is the zero of the sum.
520
+ - A scale of a sum is the sum of the scales of its parts.
521
+
522
+ Property tests hold each of these laws on generated demands, with rates and levels in different units.
523
+
524
+ Two demands add only when they agree. A class of the two demands has an equal request in each. Rates that count different things do not add, for example `{request}/s` and `{event}/s`.
525
+
526
+ ### From a demand to the value of a law
527
+
528
+ This example uses a law with the variables `rate`, `body` and `heap`.
529
+
530
+ ```ts
531
+ import { lawValue, loadPointOf, shareOf } from "@mark1russell7/capacity";
532
+
533
+ // The demand on one of four instances, then the cost of one request of the class `write` there.
534
+ const share = shareOf(workload, 4);
535
+ if (share.tag === "ok") {
536
+ const point = loadPointOf(share.value, "write", law, { heap: { value: 512, unit: "MiB" } });
537
+ // point.value: { rate: 25, body: 4096, heap: 512 }
538
+ if (point.tag === "ok") lawValue(law, point.value);
539
+ }
540
+ ```
541
+
542
+ `loadPointOf` finds one amount for each variable of the law, and converts it to the unit of the variable:
543
+
544
+ - The variable `rate` is the rate of the class.
545
+ - Each other variable is a variable of the request of the class, a level of the demand, or an amount of `given`.
546
+ - The amounts of `given` are the state of an instance, for example the size of its heap.
547
+
548
+ It gives a problem for a variable with no amount, and for a variable with two amounts.
549
+
550
+ ### A workload from live metrics
551
+
552
+ `observedWorkload(observation, name)` gives the workload of a window of metrics. An observation has the count of the requests of each class in the window.
553
+
554
+ ```ts
555
+ import { observedWorkload } from "@mark1russell7/capacity";
556
+
557
+ const workload = observedWorkload(
558
+ {
559
+ origin: "https://metrics.example/shop",
560
+ from: "2026-11-18T14:00:00Z",
561
+ to: "2026-11-18T14:05:00Z",
562
+ classes: [{ id: "read", count: { value: 270000, unit: "{request}" }, request: {} }],
563
+ levels: {},
564
+ },
565
+ { id: "shop/observed", title: "The shop from 14:00 to 14:05" },
566
+ );
567
+ // workload.value.classes[0].rate: { value: 900, unit: "{request}/s" }
568
+ ```
569
+
570
+ The rate of a class is its count, divided by the seconds of the window. Thus it is the mean rate of the window. For the load at a peak, give the window of the peak.
571
+
572
+ ## The check of a workload
573
+
574
+ `checkWorkload(workload)` gives each problem of a workload, with a code and the path of the field. `readWorkload(data)` examines the shape of the data first, then it uses `checkWorkload`.
575
+
576
+ - Each id is lower-case words. Two classes do not have one id.
577
+ - A rate is a count in a unit of time, and it is 0 or more.
578
+ - Each amount is a finite value in a canonical unit.
579
+ - A variable has units of one kind in each class.
580
+ - A name is not a level and a variable. The name `rate` is only the rate of a class.
581
+ - A plan has a note. The window of a metrics source goes from a UTC time to a later UTC time.
582
+
583
+ A workload with no class is correct: an app can have no request.
584
+
585
+ ## The contract of an app
586
+
587
+ The contract of an app is one record that each app gives to the lab and to the models. The bare subjects of the lab give the same record. The file `capacity-app.json` (`APP_FILE`) at the root of the repository of an app holds its contract, in the format `capacity-app/1`. A repository with more than one subject keeps each contract next to its subject.
588
+
589
+ | Part | What it tells |
590
+ | --- | --- |
591
+ | `variables` | Each load variable: its kind, its unit and its range. A `request` variable comes with each request, a `level` stays in the app, and a `store` is in the store at the start. The run gives a `run` variable in its line `amounts`, and no workload sets it. |
592
+ | `classes` | Each kind of request: the range of its rate, its request variables and its entry. The entry is a request of HTTP with a path template, or an outside service. |
593
+ | `start` | The commands `install`, `check` and `seed`, and the process `run` with its ready signal and its lines. A command is a program and its arguments, with no shell. |
594
+ | `services` | Each outside service that the app calls, and the fake that the lab starts in its place. |
595
+ | `metrics` | Each live series of the app: a counter or a gauge, its unit and what it measures. |
596
+
597
+ The lab puts a value into each placeholder of a command before the start: `{port}`, `{store}`, `{workload}`, `{service.<id>}` and `{variable.<id>}`. `fillPlaceholders(text, values)` does this, and `requestPath(entry, amounts)` gives the path of a request of HTTP.
598
+
599
+ ### The lines of a run
600
+
601
+ The field `lines` of `start.run` names the JSON lines of the output of the run that the lab records. Each line has a `kind`, an `ev` and a `title`. The lab keeps each line of the output that is a JSON object with that `ev`.
602
+
603
+ | Kind | What the lab reads |
604
+ | --- | --- |
605
+ | `pass` | The end of one pass of the loop of the app. The lab counts the passes in the watch after ready. |
606
+ | `write` | One write of the snapshot. The fields `longestMs`, `writeMs`, `rowsMs`, `wallMs` and `cpuMs` give its times in milliseconds. |
607
+ | `readings` | One collection of the live metrics. The field `readings` is a list of `SeriesReading`: `{ series, at, value }`. `collectReadings` of `@mark1russell7/otel-ts/pull` gives this list. |
608
+ | `amounts` | The amounts of the run variables. The field `amounts` gives each run variable by its id, in its unit. The lab keeps the last line of the watch. |
609
+
610
+ `APP_LINE_KINDS` is the closed set of the kinds. A run with no line of a kind gives no reading of that kind.
611
+
612
+ A contract with a `run` variable has a line `amounts`. Only a store or a level variable goes into the seed as `{variable.<id>}`.
613
+
614
+ ```json
615
+ "lines": [{ "kind": "pass", "ev": "lab-pass", "title": "The end of a pass of the loop" }]
616
+ ```
617
+
618
+ ### The check of a contract
619
+
620
+ `checkApp(app)` gives each problem of a contract, with a code and the path of the field. `readApp(data)` examines the shape of the data first, then it uses `checkApp`.
621
+
622
+ - Each id is unique in its list. The name `rate` is only the rate of a class.
623
+ - Each unit is a canonical unit. Each range goes from a finite amount to the same or a larger amount. A range on the scale `log` starts above 0.
624
+ - The rate of a class is a count in a unit of time.
625
+ - A request of HTTP sets each request variable of its class, in its path or in its body. The body is in bytes.
626
+ - Each command has a program and a folder in the repository. It holds only the placeholders of its place.
627
+ - The run gets its port, the store and the URL of each service. The seed gets the store and sets each store variable. Each fake gets its port.
628
+ - The seed can get the amount of a store or a level variable. It writes the state of the app at the point, and the run opens it.
629
+ - Each series has the kind and the unit of what it measures. Two series do not measure the same thing.
630
+ - Each line of the run has an `ev` that is not empty. Two lines do not have the same kind or the same `ev`.
631
+
632
+ ### The live metrics of an app
633
+
634
+ `metricsGaps(app)` gives each part of the demand that the live metrics of the app cannot give. A gap is the rate of a class, the total of a request variable, or a level. A contract with no gap gives its whole demand from its metrics.
635
+
636
+ `observationOf(app, window, readings)` gives the observation of a window from the readings of the series. Then `observedWorkload` gives the workload of the window.
637
+
638
+ ```ts
639
+ import { observationOf, observedWorkload } from "@mark1russell7/capacity";
640
+ import { readApp } from "@mark1russell7/capacity/schema";
641
+
642
+ const app = readApp(contractData); // the data of capacity-app.json
643
+ if (app.tag === "ok") {
644
+ const window = { origin: "https://metrics.example/shop", from: "2026-11-22T14:00:00Z", to: "2026-11-22T14:01:00Z" };
645
+ const observation = observationOf(app.value, window, [
646
+ { series: "shop_read_total", at: "2026-11-22T14:00:00Z", value: 0 },
647
+ { series: "shop_read_total", at: "2026-11-22T14:01:00Z", value: 54000 },
648
+ // and the readings of the other series of the contract
649
+ ]);
650
+ // observation.value.classes[0].count: { value: 54000, unit: "{request}" }
651
+ // observedWorkload(observation.value, name).value.classes[0].rate: { value: 900, unit: "{request}/s" }
652
+ }
653
+ ```
654
+
655
+ - The count of a class is the increase of its counter (`counterIncrease`). A value below the value before it is a new start of the process, thus the increase adds the whole value.
656
+ - The mean of a request variable is the increase of its total, divided by the count of its class.
657
+ - A level is the mean of the readings of its gauge, with the same weight for each reading. Item CAP-63 adds a weight for the time of each reading.
658
+
659
+ ### A workload against its app
660
+
661
+ `appWorkloadProblems(app, workload)` examines a workload against the contract of its app. Each class of the workload is a class of the app: the class that its field `of` names, or else its id. Thus a workload can have two classes of one class of the app, for example small reads and large reads.
662
+
663
+ The rates, the amounts and the levels of the workload are in the ranges of the app. Each class of the workload gives each request variable of its class of the app.
664
+
665
+ ## The composition of laws
666
+
667
+ A composition gives one measure of a subject as a sum of laws over a demand. Layer 1 is the CPU of a bare Node server. Layer 2 is layer 1 plus the cost of the service runner.
668
+
669
+ ```json
670
+ {
671
+ "format": "capacity-composition/1",
672
+ "id": "runner/cpu",
673
+ "title": "The CPU of a server on the service runner",
674
+ "subject": "runner",
675
+ "measure": { "id": "cpu", "unit": "{core}" },
676
+ "terms": [
677
+ { "composition": "node-http/cpu" },
678
+ { "law": "runner/reply/cpu", "over": "each" }
679
+ ]
680
+ }
681
+ ```
682
+
683
+ Each term gives parts, and the value is the sum of the parts.
684
+
685
+ | Term | Its parts |
686
+ | --- | --- |
687
+ | `{ "law": id, "over": "each" }` | One part for each class of the demand, at the load point of the class |
688
+ | `{ "law": id, "over": ["read", "write"] }` | One part for each class in the list |
689
+ | `{ "law": id, "over": "instance" }` | One part at the load point of the instance, for example the memory of the process |
690
+ | `{ "composition": id }` | The value of the composition `id` over the same demand |
691
+
692
+ Each term can have a `factor`, a finite number other than 0. A law term over classes can have `"load": "total"`. Then the variable `rate` of the law is the total rate, not the rate of the class. Use it when the cost of one request changes with the load of the whole process. The garbage collection is an example.
693
+
694
+ ### A term with a base gives a change
695
+
696
+ A ladder measures one level and holds the other levels at a base point. A law of that ladder gives the whole value at its level, not the part of its level. Thus two such laws do not add. A term with a `base` gives the change of its law from the base point:
697
+
698
+ ```json
699
+ { "law": "alerts-runtime/alerts-start-persons/xeon-6975p-c/main/first/watch-peak", "over": "instance", "base": { "persons": { "value": 10, "unit": "{person}" } } }
700
+ ```
701
+
702
+ - The value is the law at the load point, less the law at the base point. The base point is the load point with the amounts of `base`.
703
+ - The term gives two parts: the part at the load point, and the part at the base point with the weight times -1. The part at the base point has `base: true`.
704
+ - The two parts read the same replicate in each row. Thus the doubt of the constant of the law cancels, and the interval is the interval of the change.
705
+ - A demand and a state with no amount of a variable of `base` stay at the base point. Then the change is exactly 0.
706
+ - The model of a sum of changes says that the levels add. The test of that model is CAP-67, the levels of alerts together.
707
+
708
+ ### The units tell the weight of a part
709
+
710
+ The weight of a part is the number that multiplies the value of its law. The quotient of the unit of the composition and the unit of the law decides it.
711
+
712
+ - A quotient with no dimension needs no rate. A law in `MiB` gives `GiB` times `1/1024`.
713
+ - A quotient that is a rate needs the rate of the part. A law in `{core}·ms/{request}` gives `{core}` times the rate of its class in `{request}/ms`.
714
+ - A different quotient is a problem. CPU time does not give memory, and a rate of `{event}/s` does not give a count of requests.
715
+
716
+ The unit of a composition is canonical. It is not a level, for example `dB`, and not an absolute temperature, because the values of these units do not add.
717
+
718
+ ### Each interval goes through the sum
719
+
720
+ ```ts
721
+ import { compositionValue } from "@mark1russell7/capacity";
722
+
723
+ const cpu = compositionValue(layer2, { laws, compositions: [layer1] }, workload, { level: 0.95 });
724
+ // cpu.value.value: the CPU of the instance, in {core}
725
+ // cpu.value.parts: the part of each term and each class, with its weight
726
+ ```
727
+
728
+ - Replicate `i` of the composition is the sum of row `i` of each law, each times its weight. Thus the interval is the share `level` of these sums. The count of rows is the least count of the laws that the composition reads.
729
+ - The range `run` is the interval plus the change from the interval to the run of each part. This sum is exact when the noise of the parts moves together. For independent noise it is wider than the true range, thus it is on the safe side for a limit.
730
+ - A factor less than 0 changes the ends of each range of its part.
731
+ - The value is an extrapolation, with `extrapolated` true, when a part reads a variable outside the range of its law.
732
+
733
+ Row `i` of each law is one draw of the doubt of that law. Laws from separate fits have independent rows.
734
+
735
+ The sum has the laws of a linear map, and property tests hold each of them:
736
+
737
+ - A factor on each term scales the value, the interval, the run and the replicates. A factor less than 0 turns each range.
738
+ - The order of the terms does not change the value.
739
+ - A nested composition gives the value of its terms in line, times its factor.
740
+ - A composition of constant costs scales with the demand, and the sum of two demands gives the sum of the values.
741
+
742
+ ### The check of a composition
743
+
744
+ `checkComposition(composition)` gives each problem of a composition, with a code and the path of the field. `readComposition(data)` examines the shape of the data first.
745
+
746
+ - Each id is lower-case words, and the title is not empty.
747
+ - A composition has one term or more. A list of classes is not empty, and it has each class one time.
748
+ - A term over the instance does not read the rate of a class.
749
+ - A base names one variable or more. Each name is a name, not `rate`, and each amount is finite.
750
+ - A composition does not name itself.
751
+
752
+ `compositionValue` also finds these problems:
753
+
754
+ - A missing law or composition, and a cycle of compositions.
755
+ - A base that names a variable that its law does not have, or an amount in a unit that does not convert.
756
+ - Two records with one id.
757
+ - A law with too few replicates for the level. Each problem of a part has the path of its term in front, for example `terms[0].write.rate`.
758
+
759
+ ### The compositions of the service runner
760
+
761
+ The folder `compositions` holds the composition files: `compositions/<subject>/<cpu>/<measure>.composition.json`. Each term names a law file of the folder `laws`.
762
+
763
+ | Composition | Its terms |
764
+ | --- | --- |
765
+ | `node-http/xeon-6975p-c/cpu` | The law `cpu.request` of the plan `rate`, over each class, at the total rate |
766
+ | `node-http/xeon-6975p-c/memory` | The law `memory.high` of the plan `rate`, over the instance |
767
+ | `node-http-service/xeon-6975p-c/cpu` | The composition `node-http/xeon-6975p-c/cpu`, and the law `cpu.request.overhead`, over each class, at the total rate |
768
+ | `node-http-service/xeon-6975p-c/memory` | The composition `node-http/xeon-6975p-c/memory`, and the law `memory.high.overhead`, over the instance |
769
+
770
+ The CPU is in `{core}`, and the memory is in MiB. A demand has one class at the rate. Each interval holds 0.95 of the replicates.
771
+
772
+ | Measure | Requests each second | Layer 1 | Layer 2 | The part of the runner | Its share of layer 2 |
773
+ | --- | --- | --- | --- | --- | --- |
774
+ | CPU | 100 | 0.027 [0.026, 0.028] | 0.050 [0.048, 0.052] | 0.023 [0.022, 0.025] | 46 % |
775
+ | CPU | 1000 | 0.090 [0.089, 0.092] | 0.234 [0.228, 0.241] | 0.144 [0.138, 0.149] | 61 % |
776
+ | CPU | 2000 | 0.131 [0.129, 0.133] | 0.365 [0.360, 0.372] | 0.235 [0.229, 0.241] | 64 % |
777
+ | CPU | 4000 | 0.189 [0.187, 0.192] | 0.553 [0.545, 0.561] | 0.364 [0.356, 0.371] | 66 % |
778
+ | CPU | 8000 | 0.276 [0.274, 0.279] | 0.791 [0.757, 0.827] | 0.515 [0.481, 0.551] | 65 % |
779
+ | Memory | 100 | 30.1 [30.0, 30.1] | 31.1 [30.8, 31.5] | 1.1 [0.8, 1.4] | 3 % |
780
+ | Memory | 1000 | 30.1 [30.1, 30.2] | 40.0 [39.8, 40.3] | 9.8 [9.7, 10.2] | 25 % |
781
+ | Memory | 2000 | 30.2 [30.2, 30.2] | 40.5 [40.3, 40.8] | 10.3 [10.1, 10.7] | 25 % |
782
+ | Memory | 4000 | 30.3 [30.3, 30.4] | 40.8 [40.4, 41.2] | 10.5 [10.1, 10.8] | 26 % |
783
+ | Memory | 8000 | 30.6 [30.6, 30.7] | 40.1 [39.8, 40.6] | 9.5 [9.2, 9.9] | 24 % |
784
+
785
+ - **The runner uses more CPU than the server.** From 1000 requests each second, the part of the runner is approximately 1.5 to 2 times the CPU of the bare server.
786
+ - **The CPU laws read the total rate.** The CPU time of one request falls as the load of the process increases, thus each class reads the total rate.
787
+ - **The sum holds only over one base.** An overhead law is a difference in one job. Thus its composition adds it to the laws of its base subject, with the same conditions.
788
+ - **The range of layer 2 is 100 to 8000 requests each second**, the range of the overhead laws. The laws of layer 1 go to 36000.
789
+
790
+ A test reads each composition file with `readComposition`. The id of each composition is its path. It has a value at each end of the range of its laws, with no extrapolation. A test also holds the part of the runner above 0 at each end of the range.
791
+
792
+ ### The compositions of alerts
793
+
794
+ | Composition | Its terms |
795
+ | --- | --- |
796
+ | `alerts-runtime/xeon-6975p-c/cpu` | The law `watch-cores` of the plans `alerts-start-event`, `alerts-start-persons`, `alerts-start-feeds`, `alerts-start-log` and `alerts-start-incidents`, over the instance |
797
+ | `alerts-runtime/xeon-6975p-c/memory` | The law `watch-peak` of the same five plans, over the instance |
798
+ | `alerts-runtime/xeon-6975p-c/heap` | The law `watch-heap-peak` of the same five plans, over the instance |
799
+
800
+ - The law of the events gives the whole value. Its variable `event` is a level of the demand, in `{event}/s`.
801
+ - The laws of the persons and the feeds are terms with a base: 10 persons and 10 feeds, the base point of the ladders.
802
+ - The laws of the log are terms with a base of 16 MiB, for the memory, the heap and the CPU.
803
+ - A demand of alerts is `{ classes: [], levels: { event, persons, feeds, log } }`. A scale of the demand scales each level in it.
804
+ - A level that does not grow with the load goes in the option `given` of the query. An example is 2 persons when the events grow.
805
+ - A demand with only `event` gives the values of the compositions before CAP-37.
806
+
807
+ ## An instance type
808
+
809
+ An instance type is one size of a machine or a container: the amount of each resource of one instance. It is plain data, thus an instance file is JSON. Its format is `capacity-instance/1`.
810
+
811
+ | Field | What it is |
812
+ | --- | --- |
813
+ | `id` | The id of the instance type, for example `container/small`. |
814
+ | `title` | One line that tells a person what the instance type is. |
815
+ | `resources` | The amount of each resource, by its name. Each amount is above 0. |
816
+
817
+ ```json
818
+ {
819
+ "format": "capacity-instance/1",
820
+ "id": "container/small",
821
+ "title": "A container with 2 cores and 4 GiB of memory",
822
+ "resources": {
823
+ "cpu": { "value": 2, "unit": "{core}" },
824
+ "memory": { "value": 4, "unit": "GiB" },
825
+ "network": { "value": 1, "unit": "Gbit/s" }
826
+ }
827
+ }
828
+ ```
829
+
830
+ Three names have one meaning in each instance. A resource with one of these names is in a unit that converts to the unit of this table:
831
+
832
+ | Resource | Unit | What it is |
833
+ | --- | --- | --- |
834
+ | `cpu` | `{core}` | The CPU time that the instance gives in a unit of time. |
835
+ | `memory` | `B` | The memory of the instance. |
836
+ | `network` | `bit/s` | The rate of the network of the instance. |
837
+
838
+ An instance can have more resources, for example `disk`. No resource is necessary by name: a limit names the resource that it reads.
839
+
840
+ An instance is the resources with no name, as a demand is the load of a workload with no name. `loadPointOf` takes the resources as `given`, for a law that has a resource as a variable.
841
+
842
+ ## Limits
843
+
844
+ A limit is a ceiling on one measure, with headroom. A limit set is a list of limits with a name. It is plain data, thus a limits file is JSON. Its format is `capacity-limits/1`.
845
+
846
+ | Field | What it is |
847
+ | --- | --- |
848
+ | `id` | The id of the limit, for example `cpu`. |
849
+ | `measure` | The id of the measure that the limit holds, for example `cpu` or `latency.p99`. |
850
+ | `ceiling` | The amount that the measure does not pass: a fixed amount, or a resource of the instance. |
851
+ | `headroom` | The share of the ceiling that stays free: 0 or more, and below 1. |
852
+
853
+ ```json
854
+ {
855
+ "format": "capacity-limits/1",
856
+ "id": "web/default",
857
+ "title": "The limits of a web service",
858
+ "limits": [
859
+ { "id": "cpu", "measure": "cpu", "ceiling": { "kind": "resource", "resource": "cpu" }, "headroom": 0.3 },
860
+ { "id": "memory", "measure": "memory", "ceiling": { "kind": "resource", "resource": "memory" }, "headroom": 0.2 },
861
+ { "id": "sent", "measure": "network.tx", "ceiling": { "kind": "resource", "resource": "network" }, "headroom": 0.5 },
862
+ {
863
+ "id": "latency",
864
+ "measure": "latency.p99",
865
+ "ceiling": { "kind": "amount", "amount": { "value": 200, "unit": "ms" } },
866
+ "headroom": 0.1
867
+ }
868
+ ]
869
+ }
870
+ ```
871
+
872
+ The amount of a limit is its ceiling, times 1 less the headroom. On the instance above, the limit `cpu` has the amount 1.4 cores, and the limit `latency` has the amount 180 ms.
873
+
874
+ A ceiling that is a resource follows the instance: a larger instance gives a larger amount. A ceiling that is a fixed amount is equal on each instance.
875
+
876
+ A limit set names no instance. Thus one limit set serves each instance type.
877
+
878
+ ### The limits files of the gates
879
+
880
+ The folder `limits` holds the limits files that the lab gives from CI runs. The CI gate of an app reads its file at a commit of this repository.
881
+
882
+ | File | The gate | How the lab gives it |
883
+ | --- | --- | --- |
884
+ | `limits/alerts-start-gate.limits.json` | The start of alerts: the used heap, the peak of the resident set and the time to ready, at two sizes of the log and at 40000 routes | The plan `alerts-start-gate` and the command `start-limits.main.ts`. The README of the lab tells them. |
885
+
886
+ Each point of a start limits file holds one limit set of the format `capacity-limits/1`. A test of the lab reads the file.
887
+
888
+ ### The instance files
889
+
890
+ The folder `instances` holds the instance files, one instance type in each file. The id of each type is its path. A test reads each file with `readInstance`.
891
+
892
+ | Instance type | CPU | Memory | Heap | Where the amounts come from |
893
+ | --- | --- | --- | --- | --- |
894
+ | `small-cloud-1gb` | 0.25 core | 676 MB | 556 MB | A small cloud machine with 1 GB that runs alerts. Its CPU is the baseline share of a shared core. Its memory is the free memory before the start of alerts. |
895
+ | `lab-target-1gb` | 2 cores | 1011 MB | 556 MB | The target of the lab: the limits of its container and the heap limit of V8 |
896
+
897
+ The limits file `limits/alerts-scale.limits.json` holds the limits of one copy of alerts:
898
+
899
+ | Limit | Ceiling | Headroom | Why |
900
+ | --- | --- | --- | --- |
901
+ | `cpu` | The CPU of the instance | 0.3 | The baseline of a shared core is a mean. A burst of events needs more for a short time. |
902
+ | `memory` | The memory of the instance | 0.2 | The law gives the peak of a watch of 180 s. A longer run and a larger log give higher peaks. |
903
+ | `heap` | The heap limit of V8 | 0.2 | The same reason as the memory |
904
+
905
+ ### What an instance type and a limit do not have
906
+
907
+ - An instance type does not have a price. No query reads a price at this time.
908
+ - A limit does not name a request class. The query that reads the limit gives the value of each measure.
909
+ - A limit is not a floor: no limit keeps a measure above an amount.
910
+
911
+ ## The use of a limit
912
+
913
+ | Function | What it gives |
914
+ | --- | --- |
915
+ | `limitAmount(limit, instance)` | The amount of a limit on an instance: the ceiling less the headroom. |
916
+ | `limitUse(limit, instance, value)` | The share of that amount that a value takes, and if the limit holds. |
917
+ | `limitUses(limits, instance, values)` | The use of each limit, from the largest use to the smallest. |
918
+
919
+ ```ts
920
+ import { limitUses } from "@mark1russell7/capacity";
921
+
922
+ // 900 requests in each second, with 0.5 core-milliseconds for each request.
923
+ const uses = limitUses(limits.limits, instance, {
924
+ cpu: { value: 450, unit: "{core}·ms/s" },
925
+ memory: { value: 2.88, unit: "GiB" },
926
+ "network.tx": { value: 50, unit: "Mbit/s" },
927
+ "latency.p99": { value: 45, unit: "ms" },
928
+ });
929
+ // uses.value[0]: { limit: "memory", measure: "memory", value: { value: 2.88, unit: "GiB" },
930
+ // amount: { value: 3.2, unit: "GiB" }, use: 0.9, holds: true }
931
+ ```
932
+
933
+ - A use is the value, divided by the amount of the limit. A limit holds when its use is 1 or less.
934
+ - The first use of `limitUses` is the limit that binds: the limit nearest to its amount, or the furthest above it.
935
+ - The value converts to the unit of the ceiling. A value in a unit of a different kind is a problem.
936
+ - A limit with no value is a problem, not a limit that holds.
937
+ - Two limits with equal uses keep the order of the list.
938
+
939
+ Property tests hold the laws of the use on generated limits, instances and values, with amounts in different units:
940
+
941
+ - The use follows a scale of the value, and the inverse of a scale of the ceiling.
942
+ - The use does not change with the unit of the value, or with the unit of the ceiling.
943
+ - The use, times 1 less the headroom, is the value divided by the ceiling.
944
+ - A larger instance divides the use of each resource ceiling, and it does not change the use of a fixed ceiling.
945
+ - The order of the limits does not change the use of a limit.
946
+
947
+ Two controls show that these tests find a wrong use: one use that does not read the units, and one that keeps no headroom.
948
+
949
+ ## The check of an instance type and a limit set
950
+
951
+ `checkInstance(type)` and `checkLimits(set)` give each problem, with a code and the path of the field. `readInstance(data)` and `readLimits(data)` examine the shape of the data first.
952
+
953
+ - Each id is lower-case words. The name of a resource starts with a lower-case letter, and it has only letters and digits.
954
+ - An instance has one resource or more. Each resource is a finite amount above 0, in a canonical unit.
955
+ - The resources `cpu`, `memory` and `network` convert to their units.
956
+ - A headroom is 0 or more, and below 1.
957
+ - A fixed ceiling is a finite amount above 0, in a canonical unit.
958
+ - Two limits do not have one id. Two limits can hold one measure.
959
+
960
+ A limit set with no limit is correct. `instanceProblems(instance)` and `limitProblems(limit)` examine an instance and a limit that are not in a file.
961
+
962
+ ## The scale rule
963
+
964
+ A scale model holds an instance, its limits, a composition for each measure of a limit, and the catalog of the compositions.
965
+
966
+ | Function | What it gives |
967
+ | --- | --- |
968
+ | `scaleRule(model, demand, options)` | The lowest count of instances that holds each limit at the demand, the limit that binds, and the load of the next step. |
969
+ | `countReach(model, count, demand, options)` | The highest load that a count of instances holds, as a factor of the demand, and the limit that breaks first. |
970
+
971
+ ```ts
972
+ import { scaleRule } from "@mark1russell7/capacity";
973
+
974
+ const model = { instance, limits: limits.limits, compositions: [cpu, memory], catalog };
975
+ const rule = scaleRule(model, workload, { whole: ["heap"] });
976
+ // rule.value.count: { value: 5, interval: { low: 5, high: 6 } }
977
+ // rule.value.binding: "cpu"
978
+ // rule.value.next.factor.value: 1.11, thus 5 instances hold 1.11 times the demand.
979
+ ```
980
+
981
+ - The demand divides between the instances, as in `shareOf`. A level in `options.whole` does not divide.
982
+ - Each larger count also holds each limit. A null count is more than `options.most` instances, 2 to the power 20 when the options give none.
983
+ - The binding limit needs the most instances. It is null when one instance holds each limit.
984
+ - `next` is the reach of the count. The factor of `next` is the load where the service needs one more instance.
985
+ - A count and a factor have an interval from the replicates of the laws. Row `i` of each limit reads row `i` of each law, thus the rows pair.
986
+ - The field `binds` of each limit is the share of the replicates where that limit binds.
987
+ - The flag `extrapolated` tells that a law reads a variable outside its range at the count.
988
+ - The flag `edge` tells that a composition has no value past the count, and that the edge sets the count.
989
+
990
+ The interval tells the doubt of the laws. It does not tell the noise of one run. The headroom of a limit holds that noise.
991
+
992
+ The search reads a grid along the share of one instance, `1 / n`, on a log scale. A bisection then finds each crossing. Two crossings in one step of the grid can hide the first.
993
+
994
+ Tests hold the scale rule and the reach against each other on generated demands: the count holds the load, and one instance less does not.
995
+
996
+ ### The scale rule of alerts
997
+
998
+ The test `src/scale-files.test.ts` reads the laws, the compositions, the instance files and the limits of alerts (CAP-37). The query `countReach` gives the highest rate of events that one copy holds. The laws are of alerts `a1709b9`, after AL-172.
999
+
1000
+ | Instance type | Limits | The rate of one copy, events each second | The limit that binds first | The next limits |
1001
+ | --- | --- | --- | --- | --- |
1002
+ | `small-cloud-1gb` | The limits file | 18.4 [16.1, 21.4] | `memory` | `heap` at 41.6, `cpu` at 45.1 |
1003
+ | `small-cloud-1gb` | No headroom | 28.2 [24.6, 33.0] | `memory` | `cpu` at 166, `heap` at 362 |
1004
+ | `lab-target-1gb` | The limits file | 41.6 [37.1, 52.6] | `heap` | `memory` at 51.6 |
1005
+ | `lab-target-1gb` | No headroom | 115 [87.8, past the search] | `memory` | `heap` at 362 |
1006
+
1007
+ - On the small cloud machine, the memory binds first, at less than half of the rate where the heap binds.
1008
+ - On the lab target with the limits file, the heap binds first in 84 % of the replicates, and the memory in 16 %.
1009
+ - The laws of the events end at 70 events each second. Thus each reach past 70 is an extrapolation.
1010
+ - The lab target with no headroom is not correct past 70. 5 starts reached the heap limit of V8 at the rungs 60 and 70, but a failed start gives no reading. Thus the heap laws see only the starts that fit. CAP-103 adds the failed starts to the fit.
1011
+ - Each law is of the Intel Xeon 6975P-C. The CPU of the cloud machine is a different model, thus its CPU reach is a forecast.
1012
+ - Each law is at the base point of the ladder: 16 MiB of log, 10 feeds, 10 persons and 10 incidents.
1013
+
1014
+ The persons, the feeds, the incidents and the log are levels too. A query scales one level, and the option `given` holds the others.
1015
+
1016
+ | Instance type | Limits | The load of the query | The reach of one copy | The limit that binds first | The next limits |
1017
+ | --- | --- | --- | --- | --- | --- |
1018
+ | `small-cloud-1gb` | The limits file | The events, with 2 persons and 5 feeds | 18.9 [16.5, 22.0] events each second | `memory` | `heap` at 42.5, `cpu` at 48.0 |
1019
+ | `small-cloud-1gb` | The limits file | The persons, with 0 events | 287 [281, 296] persons | `cpu` | `memory` at 1080, `heap` at 2477 |
1020
+ | `small-cloud-1gb` | The limits file | The feeds, with 0 events | 5668 [4415, 6271] feeds | `memory` | `cpu` at 8490, `heap` at 12468 |
1021
+ | `small-cloud-1gb` | The limits file | The open incidents, with 0 events at the live setup | 2790 [2602, 2979] incidents | `cpu` | `memory` at 4150, `heap` at 19478 |
1022
+ | `small-cloud-1gb` | No headroom | The persons, with 0 events | 474 [466, 485] persons | `cpu` | `memory` at 1988, `heap` at 3924 |
1023
+ | `lab-target-1gb` | The limits file | The persons, with 0 events | 2477 [2401, 2568] persons | `heap` | `memory` at 3038, `cpu` at 5049 |
1024
+ | `lab-target-1gb` | No headroom | The persons, with 0 events | 3924 [3717, 4167] persons | `heap` | `memory` at 4881, `cpu` at 8199 |
1025
+
1026
+ - At the base log of 16 MiB, 2 persons and 5 feeds hold more events than the base point of 10 and 10: 18.9, not 18.4.
1027
+ - On the small cloud machine, the CPU of the persons binds first. The CPU of the watch grows as a power of the persons, with the exponent 0.74.
1028
+ - With no headroom on the lab target, the heap binds at 3924 [3717, 4167] persons. Each job of the lab started with 3000 persons and stopped on the heap with 10000.
1029
+ - The law of the persons ends at 3000, and the law of the incidents ends at 1000. Thus a reach past these values is an extrapolation.
1030
+ - At the live setup with 1000 open incidents, the memory is 408 MB, below the limit of 541 MB. Thus each count of incidents of the law fits.
1031
+
1032
+ #### The log
1033
+
1034
+ The log is a level too. Each query has 2 persons and 5 feeds in `given`, and the log in `given` for the events.
1035
+
1036
+ | The log | `small-cloud-1gb`, the limits file | `small-cloud-1gb`, no headroom | `lab-target-1gb`, the limits file | `lab-target-1gb`, no headroom |
1037
+ | --- | --- | --- | --- | --- |
1038
+ | 16 MiB, the base point | 18.9 [16.5, 22.0], `memory` | 28.8 [25.1, 33.7], `memory` | 42.5 [37.9, 57.5], `heap` | 117 [89.3, past], `memory` |
1039
+ | 64 MiB | 17.2 [15.0, 19.9], `memory` | 27.0 [23.6, 31.5], `memory` | 42.3 [33.7, 54.9], `heap` | 110 [85.1, past], `memory` |
1040
+ | 128 MiB | 16.3 [14.3, 18.9], `memory` | 26.1 [22.8, 30.4], `memory` | 42.1 [32.6, 51.1], `heap` | 106 [82.8, past], `memory` |
1041
+ | 188 MiB, the live store | 15.8 [13.8, 18.4], `memory` | 25.7 [22.3, 29.9], `memory` | 40.6 [32.0, 49.4], `memory` | 104 [81.6, past], `memory` |
1042
+ | 256 MiB | 15.4 [13.5, 17.9], `memory` | 25.3 [22.0, 29.4], `memory` | 38.9 [31.6, 47.9], `memory` | 102 [80.7, past], `memory` |
1043
+ | 382 MiB, the largest log of the contract | 14.9 [13.0, 17.3], `memory` | 24.8 [21.6, 28.8], `memory` | 36.8 [31.1, 46.0], `memory` | 100 [79.4, past], `memory` |
1044
+
1045
+ Each cell is the events each second of one copy and the limit that binds first.
1046
+
1047
+ - The live store had a log of 197,156,864 B (188 MiB) on 2026-11-22. At that log, one copy on the small cloud machine holds 15.8 events each second, not 18.9.
1048
+ - The memory of the watch grows as the logarithm of the log. Thus the reach falls slowly over the log.
1049
+ - With no events, each log of the contract fits on the small cloud machine. At 382 MiB, the memory is 336 [328, 343] MB, below the limit of 541 MB.
1050
+ - On the lab target with the limits file, the log moves the first limit from the heap to the memory between 128 MiB and 188 MiB.
1051
+ - The cells with no headroom on the lab target are past 70 events each second, thus they are extrapolations (CAP-103).
1052
+
1053
+ #### The check against the cloud copy
1054
+
1055
+ The live setup has 2 persons, 5 feeds and the live log. At 0.01 event each second, the compositions give these values. The test `src/scale-files.test.ts` holds them.
1056
+
1057
+ | Measure | Value | Interval |
1058
+ | --- | --- | --- |
1059
+ | `memory`, the highest memory of the process | 324 MB | [316, 331] MB |
1060
+ | `heap`, the highest used heap | 122 MB | [117, 136] MB |
1061
+
1062
+ A 24 h series of the cloud copy measured its resident set each 5 minutes (AL-190, from 2026-11-25). The first 10 minutes of each child are not in this table.
1063
+
1064
+ | The child of the series | The build of alerts | Hours | The resident set |
1065
+ | --- | --- | --- | --- |
1066
+ | 1 to 3 | Before AL-172 | 9 | 323 MB to 486 MB |
1067
+ | 4 | After AL-172 | 12.3 | 312 MB to 406 MB, median 368 MB |
1068
+ | 5 | After AL-172 | 0.3 | 344 MB to 392 MB |
1069
+
1070
+ - The rule before AL-172 gave 473 [462, 484] MB. The highest value of the children 1 to 3 was 486 MB.
1071
+ - The rule after AL-172 gives 324 MB. The median of the child 4 is 368 MB, and its highest value is 406 MB. Thus the rule is low by approximately 44 MB.
1072
+ - The laws come from a start and its watch in the lab. The cloud copy operates for hours, with its live incidents, routes and config. The rule does not explain the gap yet. CAP-104 finds its cause.
1073
+ - The small cloud machine gives 676 MB to the app. With 20 % of headroom, the limit is 541 MB. The highest value of the child 4 is below it.
1074
+ - 44 MB is approximately 3.2 events each second of the memory law. Thus at the live log, one copy holds approximately 12.6 events each second until CAP-104 ends.
1075
+
1076
+ #### The start of the new config
1077
+
1078
+ The plan `alerts-start-config` measures the start of alerts at the live log, at the commit `621d741`. The point `old` has the old config. Each other point adds one level of the new config, and the point `all` adds the three levels. The first Lab run (2026-11-26, 5 jobs, 30 children at each point) gave these means.
1079
+
1080
+ | Point | The live heap at ready | The peak of the resident set at ready | Readiness |
1081
+ | --- | --- | --- | --- |
1082
+ | `old` | 79.65 MB | 335.7 MB | 10.80 s |
1083
+ | `gdelt` | 79.82 MB | 338.7 MB | 10.58 s |
1084
+ | `score` | 79.82 MB | 342.1 MB | 10.49 s |
1085
+ | `chain` | 79.96 MB | 341.5 MB | 10.73 s |
1086
+ | `all` | 80.15 MB | 345.8 MB | 10.48 s |
1087
+
1088
+ - **The levels.** The three levels add 0.5 MB of live heap and approximately 10 MB of resident set at the start. They do not change the readiness.
1089
+ - **The heap of the start.** AL-172 of alerts decreased the live heap at ready from 177 MB to 80 MB. The laws of [The laws of alerts after AL-172](#the-laws-of-alerts-after-al-172) have this change.
1090
+
1091
+ The rule does not tell these parts yet. CAP-37 adds them:
1092
+
1093
+ - The test that the levels add: the events, the persons and the feeds together (CAP-67).
1094
+ - The laws of the polls and the bursts, and the lag of the event loop (CAP-36 and CAP-68).
1095
+ - The cause of the gap of 44 MB between the rule and the cloud copy (CAP-104).
1096
+ - The failed starts in the fit of the laws (CAP-103).
1097
+ - The live load of the cloud copy, and the smallest instance type that holds it.
1098
+ - What stops a second copy of alerts. Until then, the count of copies is 1.
1099
+
1100
+ ## The homes of the parts
1101
+
1102
+ | Part | Home |
1103
+ | --- | --- |
1104
+ | Units and amounts | `@mark1russell7/quantity` |
1105
+ | Means, quantiles, least squares, the fit of a separable model with its bootstrap and held-out ranks, and the tests of the gate (`binomialTest`, `holm`, `partialConjunction`) | `@mark1russell7/rigor-statistics` |
1106
+ | The outcomes of a gate: pass, block and no read (`gateOf`) | `@mark1russell7/rigor-bench` |
1107
+ | Programs and their evaluation | `@mark1russell7/vex` and `@mark1russell7/vex-domains` |
1108
+ | A value or an error | `@mark1russell7/optional` |
1109
+ | The property tests of the algebra | `@mark1russell7/rigor-testkit` on `fast-check` |