@mark1russell7/harness 0.16.16 → 0.16.17
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.
- package/README.md +55 -0
- package/build/{cell-CYOKWfwg.d.ts → cell-CeLvi_tR.d.ts} +19 -1
- package/build/image-BE9H5gIv.js.map +1 -1
- package/build/index.d.ts +227 -4
- package/build/index.js +398 -10
- package/build/index.js.map +1 -1
- package/build/layers.d.ts +1 -1
- package/build/schema.d.ts +1 -1
- package/image/Dockerfile +5 -4
- package/image/native/src/bin/resources.rs +187 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -204,6 +204,49 @@ A cell can put a qdisc at the root of the interface of its client, and judge the
|
|
|
204
204
|
- **The law of a datagram** (`EgressPacketLaw`) is `sent` or `dropped`. A sent datagram has a time band after the first arrival of its burst. A drop is at the `limit` of the queue, or at the `size` of the burst of tbf. The judge (`measureEgress`) compares each datagram with its law.
|
|
205
205
|
- **A void run.** A run is void when the client stops before its end or when the root qdisc is of another kind. A neighbour that is not permanent voids a run too. It is void too when a send fails with another error. A burst that spreads more than `spread`, or that starts more than `jitter` off its time, voids its run. The counts of the qdisc void a run when other traffic went through it. A step of the clock above 100 µs voids a run, and a read of less than the share `read` of the departures voids it too.
|
|
206
206
|
|
|
207
|
+
## The resources of a container
|
|
208
|
+
|
|
209
|
+
A lab reads the resources that a container used: its CPU time, its memory and the traffic of its devices. Each reading has its stamps on CLOCK_MONOTONIC, the clock of each line of a lab. Thus a load test puts the resources of its server next to the times of the `load` client.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import { quantity } from "@mark1russell7/quantity";
|
|
213
|
+
import { constant } from "@mark1russell7/rigor-chaos";
|
|
214
|
+
import { LOAD_PATH, loadPlanOf, openLab, resourceChange } from "@mark1russell7/harness";
|
|
215
|
+
|
|
216
|
+
// the server has 1 CPU and 512 MiB on CPU 0. The client and the reader have the CPUs 2 and 3.
|
|
217
|
+
const lab = await openLab({ ...target, limits: { cpus: 1, cpuset: "0", memory: quantity(512, "MiB") } }, "load");
|
|
218
|
+
const reader = await lab.resources({ period: quantity(1, "s"), cpuset: "2-3" });
|
|
219
|
+
const get = "GET / HTTP/1.1\r\nHost: target\r\n\r\n";
|
|
220
|
+
const load = loadPlanOf([{ key: "get", plan: { profile: constant(200, 30_000), options: { arrivals: "uniform" } }, requests: [get] }]);
|
|
221
|
+
const args = [lab.targetIp, String(lab.targetPort), "--plan", LOAD_PATH];
|
|
222
|
+
const probe = await lab.probe(args, [{ content: load.content, target: LOAD_PATH }], undefined, { cpuset: "2-3" });
|
|
223
|
+
await probe.until(["ready"], 15_000);
|
|
224
|
+
const before = await reader.read();
|
|
225
|
+
await probe.go();
|
|
226
|
+
await probe.until(["done", "deadline", "fail"], 60_000);
|
|
227
|
+
const used = resourceChange(before, await reader.read());
|
|
228
|
+
console.log(used.cpu?.total, used.network?.tx.bytes, used.memory.peak, reader.series.length);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- **The limits of a container** (`ContainerLimits`). `Target.limits` gives the limits of the target of `openLab`. The fourth argument of `lab.probe` gives the limits of a client.
|
|
232
|
+
- `cpus` is the CPU quota, `cpuset` is the list of CPUs, and `memory` is the memory limit. The container gets no swap.
|
|
233
|
+
- `hostLimitsOf` gives the limits as Docker takes them: `NanoCpus`, `CpusetCpus`, `Memory` and `MemorySwap`. Limits with a problem (`limitsProblems`) stop the lab before the container starts.
|
|
234
|
+
- **The reader** is `/opt/harness/resources` of the image `harness`, in a privileged sidecar (`resourceReader`). `lab.resources()` reads the target, and `probe.resources()` reads a client.
|
|
235
|
+
- The sidecar is in the network namespace of the container and in the cgroup namespace of the host. It is not in the cgroup of the container. Thus its own CPU time and memory are not in the readings.
|
|
236
|
+
- `ResourceOptions.cpuset` keeps the reader on the CPUs that it names, for example the CPUs of the client.
|
|
237
|
+
- **A reading** (`ResourceReading`) has the counters of one moment, between its two stamps (`t0`, `t1`):
|
|
238
|
+
- `cpu.stat`: the CPU time (`usage`, `user`, `system`), the periods of the CPU limit, and the count and the time of its stops.
|
|
239
|
+
- `memory.current`, `memory.peak`, and `anon`, `file`, `kernel` and `sock` of `memory.stat`. The counts of `memory.events` include `oom_kill`: the tasks that the kernel stopped at the memory limit.
|
|
240
|
+
- `pids.current`, and the bytes and the packets of each device of `/proc/net/dev` without `lo`, with their sums.
|
|
241
|
+
- The limits as the kernel prints them: `cpu.max`, `memory.max` and `cpuset.cpus.effective`.
|
|
242
|
+
- **The two uses of a reader.** `read()` gives one reading at a named moment, for example before and after a schedule. With `period`, the reader also writes a series (`series`), one reading each period, from its start to its stop.
|
|
243
|
+
- **The change between two readings** (`resourceChange`) gives the CPU time (total, user and system) and the time that the CPU limit stopped the container. It also gives the bytes and the packets of each direction, the last memory and the peak.
|
|
244
|
+
- A counter that went down, as after a restart of the container, is in `resets`, and its part is null. The function does not give a negative amount.
|
|
245
|
+
- **No read is not a zero.** A file that the reader cannot read gives null for its values. An example is `memory.peak` on a kernel before Linux 5.19.
|
|
246
|
+
- Docker removes the cgroup of a client when its program ends. After that, a `read()` throws, and each reading of a series has null for the values of the cgroup.
|
|
247
|
+
- The traffic of a client is the traffic of the namespace that the clients of the lab share.
|
|
248
|
+
- **The parse is in TypeScript.** The reader writes the text of each file in one JSON line. `resourceReadingOf` reads that line with `cpuStatOf`, `memoryStatOf`, `cpuMaxOf`, `networkOf`, `cgroupNumber`, `cgroupLimit` and `cgroupKeyed`.
|
|
249
|
+
|
|
207
250
|
## The subjects
|
|
208
251
|
|
|
209
252
|
A subject (`Subject`, `image.ts`) is the program under test, as data. The harness does not import the program. It starts the image of the program. Thus another repository can give its own subject, with its own release in it.
|
|
@@ -242,6 +285,7 @@ From 0.11.20, the harness builds each image with the CLI of Docker (`docker buil
|
|
|
242
285
|
- `client`, the TCP client of a cell. Rust's `std::net` sets no socket option by itself, thus the measurement gets the timers of the namespace. The client also samples `TCP_INFO` each 2 ms, a second vantage on its socket. It waits in `poll()`, which does not lock the socket. A keepalive timer that finds its socket held tries again HZ/20 later.
|
|
243
286
|
- In a stream, a reply of the `client` is whole at its CRLF, or after the length of a bulk string. The client then writes a `replied` line.
|
|
244
287
|
- `load`, the open-loop driver of an HTTP/1.1 server (SYS-93). Its plan (`systems-load/1`) is a list of streams, each with a key, a schedule (`rigor-schedule/1`) and its requests. Each stream has its own connection, thus a slow reply delays only its own stream. A send does not wait for a reply. A response is whole after its `Content-Length` or its last chunk. The `sent` and `replied` lines name the stream (`k`) and the arrival (`i`), and a `replied` line names the status.
|
|
288
|
+
- `resources`, the reader of the resources of a container. `read` prints one JSON line with the text of each file of a cgroup and of `/proc/net/dev`, between two monotonic stamps. `watch` prints one line each period. Each line of a series has its place on the clock from the start of the series. Thus a slow reading does not move the later ones.
|
|
245
289
|
- `inject`, which applies a fault in one `iptables-restore` commit, with monotonic stamps around the commit. Thus the start of a fault is known in the VM. A `docker exec` from Windows comes 190 ms late at the median. With `--via DEV`, the rules go in the FORWARD chain, on the device toward one side. `--protocol` and `--handshake pass` change the match of a rule, and `inject silence` drops each packet of its namespace.
|
|
246
290
|
- `inject` also sends a signal to a process by its name (`signal`), and one command to a server of the Redis protocol (`resp`). Stamps bracket each.
|
|
247
291
|
- **The Node client image** (`image/node`) is a driver client: ioredis 6.0.0 on Node 24.21.0. The digest of the image and an npm lockfile pin them. `client-ioredis.mjs` prints the lines of the TCP client on the same clock, and it adds the status changes of ioredis as `status` lines. The same image holds the client of a group in Sentinel mode (`client-sentinel.mjs`) and the observer of its Sentinels (`observer.mjs`).
|
|
@@ -580,4 +624,15 @@ In the lab tests, each HTTP client sends two requests on one connection to a Nod
|
|
|
580
624
|
|
|
581
625
|
The lab tests also step a replica set of three members of MongoDB 9.0.4 down, and they write the free memory of the machine. They also reset a write of the MongoDB driver in flight to a set of one member. They move the leadership of a quorum queue of a cluster of three nodes of RabbitMQ 4.3.6.
|
|
582
626
|
|
|
627
|
+
The tests of `resources.ts` read recorded texts of the files of a cgroup and of `/proc/net/dev`. They test the change between two readings, a counter that went down, a file with no read, and the limits of a container.
|
|
628
|
+
|
|
629
|
+
`HARNESS_RESOURCES=1` starts the proof of the readings on real containers, in the workflow `resources.yml`. A Node server has a quota of 0.5 CPUs on CPU 0 and a memory limit of 256 MiB. The client `load` and the readers have another CPU.
|
|
630
|
+
|
|
631
|
+
- The server burns 2 s of CPU time by its own count. The CPU time of the readings is from 3 % less to 25 % more than that count. With the quota of 0.5 CPUs, the burn takes 3.8 s or more, and the limit stops the server in 20 periods or more.
|
|
632
|
+
- The server holds 64 MiB, and the anonymous memory of the readings rises by that amount, from 10 % less to 100 % more.
|
|
633
|
+
- The server sends 24 bodies of 1 MiB, and its devices sent those bytes, with 8 % more at most.
|
|
634
|
+
- The series has a reading each second, within 25 %, and the server used 0.5 CPUs between two readings of the burn, within 0.1 CPUs.
|
|
635
|
+
- The readings of the client are the control. Its CPU time is less than half of the burn, and its namespace sent less than 10 % of the bytes. Thus a reader of the wrong container fails the test.
|
|
636
|
+
- After the end of the client, a reading of its series has null for each value of its cgroup, and a `read()` throws.
|
|
637
|
+
|
|
583
638
|
`pnpm --filter @mark1russell7/harness build` writes the package for npm into `build/`.
|
|
@@ -1224,6 +1224,24 @@ interface Target {
|
|
|
1224
1224
|
* and the script of its server.
|
|
1225
1225
|
*/
|
|
1226
1226
|
readonly subject?: ImageSource;
|
|
1227
|
+
/**
|
|
1228
|
+
* These are the limits of the container of the target: its CPU quota, its CPUs and its memory.
|
|
1229
|
+
* Without them, the target has no limit.
|
|
1230
|
+
*/
|
|
1231
|
+
readonly limits?: ContainerLimits;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* These are the limits of one container of a lab, as Docker writes them into the cgroup of the
|
|
1235
|
+
* container. A measurement of the cost of a server gives the server a CPU limit and a memory
|
|
1236
|
+
* limit. It keeps the client on other CPUs.
|
|
1237
|
+
*/
|
|
1238
|
+
interface ContainerLimits {
|
|
1239
|
+
/** This count is the CPUs that the container can use, for example 1 or 0.5. It becomes the quota of `cpu.max`. */
|
|
1240
|
+
readonly cpus?: number;
|
|
1241
|
+
/** This list is the CPUs that the kernel puts the container on, as `cpuset.cpus` takes it: `0`, `2-3` or `0,2`. */
|
|
1242
|
+
readonly cpuset?: string;
|
|
1243
|
+
/** This amount is the memory limit of the container (`memory.max`), for example 512 MiB. The container gets no swap. */
|
|
1244
|
+
readonly memory?: Quantity;
|
|
1227
1245
|
}
|
|
1228
1246
|
/**
|
|
1229
1247
|
* A shipped image is an image that the harness ships, by its name. Its build context is in the
|
|
@@ -1877,4 +1895,4 @@ interface RunTopology {
|
|
|
1877
1895
|
};
|
|
1878
1896
|
}>>;
|
|
1879
1897
|
}
|
|
1880
|
-
export {
|
|
1898
|
+
export { MiddleboxEvent as $, HopEvent as A, RunGroup as At, KernelRecord as B, Stage as Bt, Fault as C, RequestPrediction as Ct, GroupPrediction as D, RunBackup as Dt, GroupPlace as E, Run as Et, HttpProbe as F, RunTopology as Ft, LoadPrediction as G, Toxic as Gt, LineMatch as H, Subject as Ht, ImageSource as I, SentinelEvent as It, MemoryOomPrediction as J, isHopPlace as Jt, LoadStream as K, WsProbe as Kt, Jitter as L, SentinelStage as Lt, HopSignal as M, RunPause as Mt, HopWrite as N, RunRoute as Nt, GroupRole as O, RunDrill as Ot, HostSysctl as P, RunStream as Pt, MemoryThrottlePrediction as Q, Kafka as R, Shipped as Rt, FabricManifest as S, Replies as St, Group as T, RttRange as Tt, LoadBand as U, Target as Ut, LineCount as V, StageBand as Vt, LoadPlan as W, Topology as Wt, MemoryPrediction as X, MemoryOomTask as Y, latestEndOf as Yt, MemoryStep as Z, DriverStep as _, Reconnects as _t, ClientCapability as a, PauseBand as at, EgressPrediction as b, ReplicaSet as bt, ClusterClientAt as c, PortsPrediction as ct, ContainerLimits as d, ProxyHop as dt, MiddleboxExpectation as et, CountBand as f, ProxyTime as ft, DriverBand as g, QueuePrediction as gt, DrillRoom as h, QueueEnd as ht, Client as i, Pair as it, HopPlace as j, RunPart as jt, Hop as k, RunFabric as kt, ClusterStage as l, Prediction as lt, Drill as m, QueueConnection as mt, CLIENT_CAPABILITIES as n, Observer as nt, ClientImage as o, PausePrediction as ot, DeliveryPrediction as p, QueueBand as pt, MemoryLimits as q, environmentProblems as qt, Cell as r, Outcomes as rt, Cluster as s, PinnedImage as st, BuildImage as t, MiddleboxForm as tt, ConntrackPrediction as u, ProbeEvent as ut, EgressBurst as v, Recovers as vt, FaultPlace as w, RouterHop as wt, Fabric as x, ReplicaSetStage as xt, EgressPacketLaw as y, Reference as yt, KafkaPause as z, ShippedImage as zt };
|