Documentation
¶
Overview ¶
Command dirbench is a MEASUREMENT TOOL, not product code (bogworks/mash#43, "directory polling grows with the square of the endpoint count"). It simulates N endpoints against a NATS cluster that is already running: each one has its own connection, polls the directory the way internal/endpoint does (a filtered stream info for the keys, then one direct get per key, 64 at a time, five second timeout), publishes a heartbeat on agents.hb.cc.<owner>.<name> and counts what its agents.hb.*.<owner>.* subscription delivers. It does not sign or verify anything and does not import the Endpoint. It creates a bucket of its OWN, named dirbench-<8 random hex>, with the product's directory config (store.DirectoryConfig: history, storage; replicas settable by flag), writes N valid records, runs a warm-up and then a measured window, and prints key=value lines: client counters, and server side numbers from /varz deltas and /proc (CPU, RSS) of the server pids it is given.
SCRATCH SERVERS ONLY. The tool refuses to start unless every -urls host is loopback (127.0.0.0/8, ::1, localhost), or -i-know-this-is-a-scratch-server is passed. It only ever creates its own uniquely named bucket (after checking that neither the bucket nor its stream exists), never touches any other bucket, stream or key, and deletes only that bucket at the end, on error and on SIGINT/SIGTERM. It still loads the server with N connections and polls: do not point it at a deployment.
-mode old (default) is the behaviour measured in docs/evidence/2026-11-02-directory-polling: every poll is a full load. -mode new runs each endpoint's poll through endpoint.DirPoller, the decision logic of ADR 0065 (one unfiltered stream info per poll, a full load only when the state moved or the forced reload is due, jittered waits).
-hb-mode (docs/evidence/2026-11-02-heartbeat-fanout) varies the heartbeat side: all (default, today) = every endpoint publishes a heartbeat and holds the standing agents.hb.*.<owner>.* subscription; none = it publishes but holds no heartbeat subscription; probe = none plus each endpoint answers $SRV.INFO.agents with a -who-payload byte registration-like reply and runs a who probe every -who-every (random first offset; 0 = none) or all at once once (-who-burst): subscribe a fresh inbox, publish the request, wait endpoint.PresenceQuiet after the last reply or endpoint.PresenceCap. Each endpoint's who calls go through the real endpoint.PresenceCache (ADR 0066): a call within -who-gap (default 30s, the product's endpoint.PresenceCacheTTL) of its last successful probe is a cache hit and sends nothing; -who-gap 0 makes every call probe, as the numbers in docs/evidence/2026-11-02-heartbeat-fanout/results.txt were taken.
Usage: go run ./scripts/dirbench -urls a,b,c -mon http://..,.. -pids 1,2,3 -n 100 [-sync] [-replicas 1] [-mode old|new]
[-hb-mode all|none|probe] [-who-every 5m] [-who-burst] [-who-payload 600] [-who-gap 30s]