Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,42 @@ is `0`, minor versions may carry breaking changes — they are called out here.

## [Unreleased]

### Added
- **One trace per business event** (ADR-0034, lot A). The runtime carries a W3C
`traceparent` in a NATS header on every message it publishes, so the spans of
one event, from the source or webhook through each flow and `invoke` to the
sink, form one trace with parent links. `http-in` and `api` flows continue a
caller's trace, and `http-in` answers with the trace id. `http-out` and
`slack-out` send `traceparent` downstream, and an `exec` sink gets it as
`TRACEPARENT`. A dead letter keeps its trace and a replay continues it. The
event ring and the `dead-lettered` event show the trace id. Transport test T6
checks the chain in CI against a stub collector, a graceful stop included.
- **The OTLP exporter reads the standard variables:** the traces endpoint,
headers (never logged) and timeout, `OTEL_RESOURCE_ATTRIBUTES`, the six
samplers of `OTEL_TRACES_SAMPLER`, and the batch variables `OTEL_BSP_*`. It
retries connection errors, 429, 502, 503 and 504 with backoff, flushes its
queue on a graceful stop, and counts on `/metrics` what it sends and what it
loses (`vejas_spans_exported_total`, `vejas_spans_dropped_total{reason}`).

### Changed
- Spans have a new shape. The name is still the unit and the old attributes
stay, but the kind now says what the hop was (`SERVER`, `PRODUCER`,
`CONSUMER`, `CLIENT`, `INTERNAL` instead of `CONSUMER` everywhere), new
attributes follow the OpenTelemetry semantic conventions (`messaging.*`,
`error.type`) and carry the flow version, and a success leaves the status
unset instead of `OK`. A query or dashboard that filters on kind or status
may need updating.
- The trace context travels even without an exporter, so a downstream system
and the event ring get it. It costs about 3 µs of CPU per flow hop; exporting
every span about 10 µs (see the benchmarks page).

### Corrected
- The observability guide said an end-to-end request shows up as a trace across the
pipeline. It does not: every span carries a fresh trace id and no parent, so a
request that crosses three flows is three unrelated traces in the collector. The
guide now says so, and says the cost of the OTLP exporter and of the event ring has
not been measured separately. ADR-0034 (Proposed) decides how one trace per event
gets built; the guide will claim it once its CI test passes.
not been measured separately. ADR-0034 decided how one trace per event gets
built, and it is built in this release: see Added.

### Security
- **url 2.5.8 → 2.5.9** in the runtime and in the `mq` and `amqp` connectors, for
Expand Down
38 changes: 38 additions & 0 deletions bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,44 @@ harness and the same program: **18 643 evt/s** at 16 publishers (17 265 at
about 20 µs per event under load and under 10 µs in isolation (its own
`throughput_probe`). Same consumer path, same publish-before-ack barrier.

## What tracing costs (ADR-0034, `bench/trace-cost.sh`)

`bench/trace-cost.sh` runs the isolated flow hop above in each tracing
configuration, interleaved, five times each (20 000 events, four
publishers), and reads the runtime's own CPU time from `/proc`. With four
publishers the rate is theirs; the CPU time is the runtime's. Spans go to a
collector that only counts them (`bench/otlp-discard.py`). 2026-11-26, same
machine; the runtime from before tracing is master at `491ba69`, passed as
`BASE_BIN`:

| Configuration | Flow-hop rate | Runtime CPU per event | RSS |
|---|---|---|---|
| Before tracing | 9 390/s | 72.5 µs | 9.7 MB |
| Context propagated, no exporter | 9 403/s | 74.0 µs | 10.4 MB |
| Every span exported | 9 166/s | 83.0 µs | 12.3 MB |
| One trace in ten exported | 9 204/s | 76.5 µs | 12.0 MB |
| Before tracing, events carrying `traceparent` | 8 718/s | 71.0 µs | 9.5 MB |
| No exporter, events carrying `traceparent` | 8 632/s | 78.5 µs | 10.5 MB |
| Every span exported, events carrying `traceparent` | 8 669/s | 88.0 µs | 12.6 MB |

The 200 000 spans of the "every span" runs all reached the collector, and
10 023 of the 100 000 events sampled at one in ten. Over four series the
context alone measured between 1.5 and 4.5 µs; over three, export held at 10
to 10.5 µs over the runtime from before tracing. Events that carry a header slow the
publishers (the `nats` CLI sends it) as much before tracing as after.

Two findings on the way, both fixed before the numbers above:

- **#8 One HTTP request per handful of spans.** The first exporter posted
whatever its queue held and built a JSON tree per span: export cost 63 µs
of CPU per event over the same runtime without an exporter. Batching as
the OpenTelemetry SDKs do (512 spans or 1 s, `OTEL_BSP_*`) and writing the
JSON directly brought it to 28 µs.
- **#9 Waking the exporter for every span.** An exporter that waits on its
queue has every producer wake it, a futex call and a context switch per
span. Reading the queue on a 25 ms tick while spans are pending brought
export to between 5.5 and 9 µs.

## The true hop ceiling and multi-flow scaling

With parallel publishers, the single-flow hop tops out around **14–16 k/s**
Expand Down
20 changes: 16 additions & 4 deletions bench/flow-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
# plain NATS subscription. This is the interpreter + JetStream number — what
# the end-to-end pipeline can hope for once the I/O ceilings fall.
# bench/flow-only.sh [count] (needs the `nats` CLI)
# BIN=<path> runs another binary (a before/after comparison). With
# BENCH_TRACEPARENT=<traceparent> the events carry that header, so the flow
# continues a trace instead of starting one; OTEL_EXPORTER_OTLP_ENDPOINT, if
# set, reaches the runtime and turns span export on (ADR-0034, point 6).
set -euo pipefail
cd "$(dirname "$0")/.."

N="${1:-20000}"
PUBS="${PUBS:-4}" # parallel publishers — one sequential publisher caps ~2.8k/s
N=$(( (N / PUBS) * PUBS )) # keep the count exactly divisible
BIN="core/target/release/vejas-runtime"
BIN="${BIN:-core/target/release/vejas-runtime}"
NATS_PORT=4224
STORE=$(mktemp -d)
ROOT=$(mktemp -d)
Expand Down Expand Up @@ -45,10 +49,13 @@ SUB_PID=$!
sleep 0.5

EVENT=$(tr -d '\n' < bench/root/flows/fixtures/bench_orders.json)
HEADER=()
[ -n "${BENCH_TRACEPARENT:-}" ] && HEADER=(-H "traceparent:$BENCH_TRACEPARENT")
T0=$(date +%s%N)
PUB_PIDS=()
for _ in $(seq "$PUBS"); do
nats -s nats://127.0.0.1:$NATS_PORT pub vx.bench.orders --count=$((N / PUBS)) "$EVENT" > /dev/null 2>&1 &
nats -s nats://127.0.0.1:$NATS_PORT pub vx.bench.orders --count=$((N / PUBS)) \
${HEADER[@]+"${HEADER[@]}"} "$EVENT" > /dev/null 2>&1 &
PUB_PIDS+=($!)
done
wait "${PUB_PIDS[@]}"
Expand All @@ -57,16 +64,21 @@ PUB_MS=$(( ($(date +%s%N) - T0) / 1000000 ))
wait $SUB_PID
TOTAL_MS=$(( ($(date +%s%N) - T0) / 1000000 ))
RSS_KB=$(ps -o rss= -p $RUNTIME_PID | tr -d ' ')
# The runtime's own CPU time (user + system, Linux): what a change costs the
# runtime, apart from the publishers and the server it shares the machine with.
CPU_MS=$(awk -v hz="$(getconf CLK_TCK)" '{printf "%d", ($14 + $15) * 1000 / hz}' "/proc/$RUNTIME_PID/stat" 2>/dev/null || echo 0)

python3 - "$N" "$PUB_MS" "$TOTAL_MS" "$RSS_KB" << 'PY'
python3 - "$N" "$PUB_MS" "$TOTAL_MS" "$RSS_KB" "$CPU_MS" << 'PY'
import json, sys
n, pub_ms, total_ms, rss = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])
n, pub_ms, total_ms, rss, cpu_ms = (int(a) for a in sys.argv[1:6])
print(json.dumps({
"scenario": "bus -> flow (lookup + conversions + projection loop) -> bus, no HTTP anywhere",
"events": n,
"publish_ms": pub_ms,
"done_ms": total_ms,
"flow_rate_per_s": round(n / (total_ms / 1000)),
"runtime_rss_mb": round(rss / 1024, 1),
"runtime_cpu_ms": cpu_ms,
"runtime_cpu_us_per_event": round(cpu_ms * 1000 / n, 1),
}, indent=2))
PY
34 changes: 34 additions & 0 deletions bench/otlp-discard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""A collector that accepts OTLP/HTTP JSON, keeps nothing, and counts spans.

python3 bench/otlp-discard.py <port> <count-file>

bench/trace-cost.sh points the runtime at it, so the cost measured is the
runtime's, not a real collector's.
"""
import http.server
import sys
import threading

port, count_file = int(sys.argv[1]), sys.argv[2]
lock = threading.Lock()
spans = 0


class Discard(http.server.BaseHTTPRequestHandler):
def do_POST(self):
global spans
body = self.rfile.read(int(self.headers.get("content-length") or 0))
with lock:
spans += body.count(b'"spanId"')
with open(count_file, "w") as f:
f.write(str(spans))
self.send_response(200)
self.send_header("content-type", "application/json")
self.end_headers()
self.wfile.write(b"{}")

def log_message(self, *args):
pass


http.server.ThreadingHTTPServer(("127.0.0.1", port), Discard).serve_forever()
66 changes: 66 additions & 0 deletions bench/trace-cost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# What tracing costs on the flow hop (ADR-0034, point 6). Runs
# bench/flow-only.sh RUNS times per configuration, interleaved so that drift
# hits every configuration alike, and prints the medians: throughput, and the
# runtime's own CPU time per event (the better measure, since four publishers
# bound the throughput).
# bench/trace-cost.sh [runs] [events] (needs the `nats` CLI)
# BIN is the runtime under test (core/target/release/vejas-runtime). BASE_BIN,
# if set, is a runtime from before tracing (v0.6.0): the difference is what
# propagation costs with no exporter. Spans go to bench/otlp-discard.py, which
# only counts them.
set -euo pipefail
cd "$(dirname "$0")/.."
RUNS="${1:-5}"
N="${2:-20000}"
BIN="${BIN:-core/target/release/vejas-runtime}"
BASE_BIN="${BASE_BIN:-}"
COL_P="${COL_P:-4399}"
OUT=$(mktemp)
COUNT=$(mktemp)
TP="00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
EP="http://127.0.0.1:$COL_P"
python3 bench/otlp-discard.py "$COL_P" "$COUNT" &
COL=$!
trap 'kill $COL 2>/dev/null || true; rm -f "$OUT" "$COUNT"' EXIT
sleep 0.5

one() { # a label, then the environment of that configuration
local label="$1"; shift
local json
json=$(env "$@" bench/flow-only.sh "$N" 2>/dev/null)
python3 -c 'import json, sys; print(json.dumps({"config": sys.argv[1], "result": json.loads(sys.argv[2])}))' \
"$label" "$json" >>"$OUT"
echo " $label done" >&2
}
for r in $(seq "$RUNS"); do
echo "run $r/$RUNS" >&2
if [ -n "$BASE_BIN" ]; then
one "before tracing" BIN="$BASE_BIN"
one "before, caller header" BIN="$BASE_BIN" BENCH_TRACEPARENT="$TP"
fi
one "no exporter" BIN="$BIN"
one "no exporter, caller header" BIN="$BIN" BENCH_TRACEPARENT="$TP"
one "export all" BIN="$BIN" OTEL_EXPORTER_OTLP_ENDPOINT="$EP"
one "export all, caller header" BIN="$BIN" BENCH_TRACEPARENT="$TP" OTEL_EXPORTER_OTLP_ENDPOINT="$EP"
one "export 1 in 10" BIN="$BIN" OTEL_EXPORTER_OTLP_ENDPOINT="$EP" \
OTEL_TRACES_SAMPLER=parentbased_traceidratio OTEL_TRACES_SAMPLER_ARG=0.1
done
python3 - "$OUT" <<'PY'
import json, statistics, sys
by = {}
for line in open(sys.argv[1]):
row = json.loads(line)
by.setdefault(row["config"], []).append(row["result"])
ref = "before tracing" if "before tracing" in by else "no exporter"
med = lambda rows, k: statistics.median(r[k] for r in rows)
base_rate = med(by[ref], "flow_rate_per_s")
base_cpu = med(by[ref], "runtime_cpu_us_per_event")
print(f"{'configuration':<28}{'events/s':>9}{'':>9}{'CPU µs/event':>14}{'':>9}{'RSS MB':>8}")
for name, rows in by.items():
rate, cpu = med(rows, "flow_rate_per_s"), med(rows, "runtime_cpu_us_per_event")
print(f"{name:<28}{rate:>9.0f}{(rate / base_rate - 1) * 100:>+8.1f}%"
f"{cpu:>14.1f}{(cpu / base_cpu - 1) * 100:>+8.1f}%{med(rows, 'runtime_rss_mb'):>8}")
print(f"(medians of {len(by[ref])} runs; percentages against '{ref}')")
PY
echo "spans received by the collector: $(cat "$COUNT")"
1 change: 1 addition & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ ureq = "2"
# the hand-rolled MQTT client can wrap its stream in TLS. No new binary weight.
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12", "logging"] }
webpki-roots = "0.26"
# Seeds the trace and span ids (ADR-0034). Already in the tree through ring, so
# no new binary weight.
getrandom = "0.2"
# The Varpulis CEP engine, embedded as a library (ADR-0031): compile a VPL
# program, feed it events, publish its emits. No async runtime in its tree —
# its own CI (scripts/check-engine-deps.py) fails if one ever appears.
Expand Down
Loading
Loading