How It Works
Threads, memory, what happens when the collector is down, what it costs, and the limits worth knowing.
One background thread
- One background thread runs the reporting loop, and no request thread ever touches the network.
onRuntimeStartstarts it. - On shutdown, the module's
onUnloadstops the loop, waits up to a second for a cycle under way, and sends the goodbye with a 2 second limit. Nothing is sent after the goodbye. When a process is stopped by a signal without unloading its modules (a BoxExpress app), a JVM shutdown hook does the same. - Request threads only write to memory. The runtime's
onRequestStart,onRequestEndandonErrorevents, or BoxExpress's own, add to a per-route histogram and a bounded error queue. Every one of those calls is wrapped so nothing it does can throw into your app. Redacting and fingerprinting an error happens later, on the background thread.
Bounded memory
Request timings are a fixed-size histogram per route, never a list of requests. At most ten times maxRoutesPerHeartbeat routes are tracked; more are counted as <other>. At most maxBufferedErrors errors are held.
When the collector misbehaves
| Collector | What the module does |
|---|---|
| Unreachable | Waits 5 seconds, doubling to a 5 minute cap. Request stats for the missed intervals are merged into the next heartbeat that gets through; errors wait in their queue. Your app doesn't notice. |
409 | It no longer knows this server: register again, then resend. |
401 or 426 | Logged once at ERROR, then retried every 5 minutes. |
413 | Resent without error bodies, then without errors. |
408, 429, 5xx | Retried with the data kept. |
Any other 4xx | The collector will never take that heartbeat, so its errors and request stats are discarded, counted in the next droppedErrors, and a WARN line carries the answer. |
If building a heartbeat fails, what was taken from the buffers is put back. After three failures in a row it's discarded instead, in case that data is the cause.
What it costs
Measured on BoxLang 1.19.0 MiniServer on an Apple-silicon Mac, three runs of 300 requests each after a warm-up. The "black hole" is a collector that accepts the connection and never answers, the worst case.
| Not installed | Installed, disabled | Reporting to a black hole | |
|---|---|---|---|
| Launch to first answered request | 697–728 ms | 742–789 ms | 778–801 ms |
| Mean request time (trivial page, loopback) | 1.09–1.17 ms | 1.18–1.28 ms | 1.34–1.88 ms |
Installing the module adds roughly 50 to 80 ms to startup, and a dead collector adds nothing a request waits on. In-process, timing a request takes about 45 microseconds and capturing an error about 0.4 ms. The request means differ by less than the run-to-run noise, so read them as "a fraction of a millisecond at most". The first start after installing or upgrading is a few hundred milliseconds slower while BoxLang compiles the module.
Agent id
The collector knows a server by an agent id, a UUID generated on first start and kept in agentIdFile so it survives restarts. Deleting the file makes the server look new.
Where the file can't be written (Lambda, a read-only filesystem), the id is derived from serverName and environment, and the log says so. That id is stable but not unique: two servers with the same name and environment share it and appear as one. Give them different names, or point agentIdFile somewhere writable.
On an ephemeral filesystem that is writable (most containers), the file is written but gone with the container, so every new container registers as a new server and the old one shows as lost. Mount agentIdFile on a volume to keep one identity.
Limitations
- p50 and p95 are the upper bound of a histogram bucket (a 12 ms request reports as 15 ms), not exact values.
- Without BoxExpress's events, a route is the HTTP method and script path (
GET /index.bxm), so an app that puts ids in the path produces many routes. The route cap keeps that bounded. - A request for a missing template raises
onErrorin BoxLang, so it's counted and reported as an error. - Only datasources defined in
boxlang.jsoncan be checked by name. See Health Checks for the others. - A short CLI script registers on every run. Set
enabledtofalsefor CLI use if that's noise. runtimeTypeisminiserver,commandbox,cli,servlet,lambdaorunknown. Only MiniServer and the CLI have been checked on a real runtime; CommandBox, servlet containers and Lambda haven't been tested.