# Benchmarks Compares the request path of two revisions on one machine: the gateway, the components behind it, the broker and the database, as an application is deployed. ```shell $ npm run bench # the working tree against its merge base with origin/dev $ npm run bench -- --base alpha --head HEAD # two revisions $ npm run bench -- --scenarios token.id,list.1000 --quick $ npm run bench -- --pr 1234 --quick # a pull request, with the report posted to it $ npm run bench -- --profile # profiles of the working tree $ npm run bench -- --clean # removes what runs leave in the stack ``` ## Requirements - Linux, for `/proc`, `/sys` and `taskset`. - The compose stack of the repository, running: see [Running Features](../CONTRIBUTING.md#prerequisites). - [`oha`](https://github.com/hatoo/oha) 1.16 or later on the `PATH`. - Ports `31090`–`31099` free. - For `--pr`, `gh` signed in to an account that may comment on the pull request. ## Options | option | default | | | --------------------- | ------------------------------------- | -------------------------------------------------------------------------------------- | | `--base ` | merge base of `HEAD` and `origin/dev` | the revision compared against | | `--head ` | the working tree | the revision compared | | `--scenarios ` | all but the optional | comma-separated | | `--blocks ` | 4, or 3 with `--quick` | at least 2 | | `--window ` | 10, or 5 with `--quick` | the length of a measured window | | `--threshold ` | 0.05 | the change a verdict names | | `--quick` | | shorter windows and fewer blocks | | `--pr ` | | compares the head of that pull request with its merge base, and posts the report to it | | `--profile` | | profiles instead of a comparison | | `--ref ` | the working tree | the revision `--profile` runs | | `--clean` | | removes the vhosts and databases of both sides | `--pr` runs commits fetched from the remote, not the working tree, so the checkout may move on while it runs. A run that fails posts why instead of a report. `--base` and `--head` given with it take precedence. A revision other than the working tree is unpacked and installed under `~/.cache/toa-bench/trees`, once per commit; the three most recent are kept. `TOA_BENCH_CACHE` names another directory. The working tree runs as it is built: a source newer than its build is reported, and the build is what runs. ## What a run does Each revision runs the gateway, with its identity components, and two components of its own — `bench`, with an entity in MongoDB, and `peer`, which `bench` calls and which receives `bench`'s events — each in a process of its own. The revisions get a broker vhost and a database each, `toa-bench-a` and `toa-bench-b`. A block boots both revisions and runs every scenario on each, in turns: base, head, head, base, and head, base, base, head in the next block. Where the machine has eight logical CPUs or more, the gateways, the components and `oha` are pinned to cores of their own. A run of the default scenarios took 61 minutes on an 8-core machine; `--quick` has 3 blocks of 5-second windows. ## Scenarios | id | request | | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `small` | `GET` of a reply computed without storage | | `small.h2c` | the same over cleartext HTTP/2 | | `observe` | `GET` of one item from MongoDB | | `list.1000` | `GET` of a thousand items | | `list.1000.h2c` | the same over cleartext HTTP/2 | | `create` | `POST` of an item of fifteen fields, which emits an event `peer` receives | | `chain` | `GET` of an operation that calls `peer` | | `token.id` | `GET` under `auth:id`, with a `Token` | | `token.role` | `GET` under `auth:role`, with a `Token` | | `mcp.tools.list` | `tools/list` over MCP, on a tree of 22 tools | | `list.1000.msgpack` | optional: `list.1000` encoded as MessagePack | | `stream.1000` | optional: a window of a thousand items as a stream, a part each | | `list.1000.projected` | optional: `list.1000` on a route whose query names three properties | | `list.1000.restricted` | optional: `list.1000` on a route whose `io:output` names four properties | | `token.reissue` | optional: `GET` under `auth:id` with a `Token` older than `refresh`, sent again after the reply re-issues it, so every request pays for a re-issue — the cost of one re-issue | Tokens are issued by the run and the gateway is configured with a `refresh` of a day, so no token ages during a run. ## The report `benchmarks/results/